My route is correctly configured as I already saw it in another questions. Web API uses MapHttpRoute
, and it uses System.Web.Http
. I decorated my Actions with [System.Web.Http.HttpPost]
but it seems not to work and it returns the error message:
The requested resource does not support http method 'GET'
I tried this solution [System.Web.Http.AcceptVerbs("GET", "POST")]
as I see here on the same question. The requested resource does not support HTTP method 'GET' and it worked.
But on the API Help Page , this is what I see
the METHOD of the Action is GET
that that should be POST
.
Maybe I am missing something that should not or should be implemented on the Action I am working with.
Here is my code in the Controller.
[HttpPost, Route("DestroySession/{userID}", Name = "DestroySession"), AcceptVerbs("GET" , "POST")]
public async Task<IHttpActionResult> DestroyUserSession(string userID)
{
SystemResult systemResult = new SystemResult();
await Task.Run(() => {
IAbstractLogic<UserInput, SystemResult> systemProcess = new LogoutLogic();
UserInput userInput = new UserInput
{
UserID = userID
};
systemResult = systemProcess.doProcess(userInput);
}).ConfigureAwait(false);
return Content(HttpStatusCode.OK, new
{
message = systemResult.ResultMessage, status = systemResult.ResultCode == 0
});
}
And here is my WebApiConfig
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Any help would be much appreciated. Regards
Whooosh! It seems that my code is working very fine. I just tested it in POSTMAN and it literally works. All I can say is that if your request is to POST
something. you need a third party application to test it out. Testing it on the browser alone gives you so much problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.