I have an ASP.NET web API. I am trying to execute a POST line to an endpoint. The ASP.NET web API endpoint is as follows:
[HttpPost]
public async Task<IHttpActionResult> Test(string name)
{
int i = 0;
i = i + 1;
return Ok();
}
In Fiddler, I execute the following request from the composer:
POST http://localhost:8089/api/MyApiController/test
If I remove the "string name" as a parameter, I can successfully execute the API endpoint. When there is a line name, I get 405 error. So, I added the following in the "Request body" section in Fiddler:
John
Unfortunately, this still causes a 405 surge. I cannot say if the web API endpoint will be configured incorrectly if I misconfigure my request in the violin. My complete request is as follows:
POST http://localhost:8089/api/MyApiController/test HTTP/1.1
User-Agent: Fiddler
Host: localhost:8089
Content-Length: 26
Content-Type: application/json; charset=utf-8
{ "name" : "John"}
The answer is as follows:
HTTP/1.1 405 Method Not Allowed
Cache-Control: no-cache
Pragma: no-cache
Allow: GET
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-SourceFiles: =?UTF-8?B?QzpcRWNvZmljXFNvbGlkUVxKTExcamxsLW1hcmtldHNwaGVyZVxXZWJzaXRlXGFwaVxTZWFyY2hBcGlcaW5kZXg=?=
X-Powered-By: ASP.NET
Date: Fri, 12 Dec 2014 15:51:50 GMT
Content-Length: 73
{"Message":"The requested resource does not support http method 'POST'."}
I do not understand why POST is allowed when I do not have a parameter. However, when I add the parameter, POST does not work.
[]
# :
var content = await Request.Content.ReadAsStringAsync();
, JSON content. content - .