You can't bind a single primitive string using json and FromBody, json will transmit an object and the controller will expect an complex object (model) in turn. If you want to only send a single string then use url encoding.
On your header set
Content-Type: application/x-www-form-urlencoded
The body of the POST request message body should be =saeed
(based on your test value) and nothing else. For unknown/variable strings you have to URL encode the value so that way you do not accidentally escape with an input character.
Create a model and use that instead.
Message body value: {"name":"saeee"}
c#
public class CustomModel {
public string Name {get;set;}
}
Controller Method
public HttpResponseMessage Post([FromBody]CustomModel model)
Pass primitive strings to your post using the URI instead of the message body.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments