Reputation: 620
I am currently having issues with getting both request to work together.
When I use [FromUri]
, I am unable to filter POST request in fiddler but I am able to call GET request in any browser.
But When I use [FromBody]
, I am then unable to request GET method but I am able to filter POST request, in fiddler.
(e.g. GET request --> localhost/api/test?name=bbcm)
(e.g. POST request:
[request header]
--> User-Agent: Fiddler
Content-Type: application/json;
Host: localhost:45361
Content-Length: 16
Authorization: Basic #####=
[request Body]
--> {"name":"bbcm"})
[Authorize]
[HttpGet]
[HttpPost]
public HttpResponseMessage post([FromUri] Query query)
{
// do something
var data = Data.ToList();
if (!data.Any())
{
var message = string.Format("No data found");
return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
}
return Request.CreateResponse(HttpStatusCode.OK, data);
}
}
Am I calling the request incorrectly or would I need to change its of my code to make this work. Please advice. Many thanks
Upvotes: 0
Views: 225
Reputation: 536
Simply create a single POST method and a single GET method and a private method that is called from both of them. This allows to take the input parameters correctyl for the desired methods.
You can still access the GET parameters in the POST method context via the Request object if you really need.
Upvotes: 1