is this how you are suppose to use update using api in asp.net?
This code shows error response 405 but my api is working fine
if you dont understand what I am saying please tell me i will try my best
13 Replies
Why are you using HttpClient to call one method from another...?
Also, don't use
.Result
, never ever ever
Use proper asynchronous code and await
it
Also also, ditch Newtonsoft.Json
and use System.Text.Json
ok
uhh what do you mean? like use httpClientFactory
No, I mean why are you calling the API in the controller?
Presumably, both are in the same project?
both are different project but they are running locally
Ah, well, that changes things I guess
And also makes me question why are they two different projects
where should I call it what is the strandard?
You should... not be calling the API from the controller
i am learning to make api and integrate
This project should also be connected to the database
And should be calling that database
to teh same database?
Ah, so the MVC project is supposed to be the API consumer, then?
Yes, you can connect more than one project to a database
yes
Carry on, then
Far as the error goes...
405
means "method not allowed"
So you're trying to POST
to a PUT
endpoint, GET
from a DELETE
endpoint, etc