frombodyattribute

REST API: GET request with body

别等时光非礼了梦想. 提交于 2019-11-27 06:35:50
问题 I want to implement a REST API and need a body on my GET requests. (Like discussed here: HTTP GET with request body) Are there http clients which are not able to send a body with a GET request? Fiddler is able to do it, although the message box is red. 回答1: As a general rule, the idea of a GET in REST is that any of your parameters are sent in the URL. As the answer on the question you included indicates, it's doable but misses the point of REST, which is to have a consistent webbish

Reading FromUri and FromBody at the same time

淺唱寂寞╮ 提交于 2019-11-27 01:49:12
I have a new method in web api [HttpPost] public ApiResponse PushMessage( [FromUri] string x, [FromUri] string y, [FromBody] Request Request) where request class is like public class Request { public string Message { get; set; } public bool TestingMode { get; set; } } I'm making a query to localhost/Pusher/PushMessage?x=foo&y=bar with PostBody: { Message: "foobar" , TestingMode:true } Am i missing something? A post body is typically a URI string like this: Message=foobar&TestingMode=true You have to make sure that the HTTP header contains Content-Type: application/x-www-form-urlencoded EDIT :

Reading FromUri and FromBody at the same time

送分小仙女□ 提交于 2019-11-26 09:48:18
问题 I have a new method in web api [HttpPost] public ApiResponse PushMessage( [FromUri] string x, [FromUri] string y, [FromBody] Request Request) where request class is like public class Request { public string Message { get; set; } public bool TestingMode { get; set; } } I\'m making a query to localhost/Pusher/PushMessage?x=foo&y=bar with PostBody: { Message: \"foobar\" , TestingMode:true } Am i missing something? 回答1: A post body is typically a URI string like this: Message=foobar&TestingMode