I am creating a web api that needs to accept JSON as input that is sent by the called client side application. Below is the Code
public class SetNameController : ApiController
{
[HttpPost]
public async Task<IHttpActionResult> Get([FromBody] CodeDTO.RootObject bCode)
{
string Bar_Code = bCode.Barcode.ToString();
if (Bar_Code == "" || Bar_Code == null)
{
....
return OK(response)
}
Here I am not sure How the client application call this Web API, the URL can be just like http://localhost:41594/api/SetName can it accept the JSON? Also can I test this using PostMan or Fiddler?
-
2Should be '/api/SetName/Get'. Pass the bCode parameter formatted as JSON in the request body. As a side note naming the action 'Get' but decorating it with '[HttpPost]' is confusing.Valuator– Valuator2017年10月31日 17:59:41 +00:00Commented Oct 31, 2017 at 17:59
-
Show the screen of the postmanHussein Salman– Hussein Salman2017年10月31日 18:00:22 +00:00Commented Oct 31, 2017 at 18:00
1 Answer 1
Specify the following:
- Method: POST
- Header: Content Type
Then, provide the payload json data in Body as raw:
Also, change the name of the action Get which might cause confusion. If you still cannot hit your api, you can use route urls by decorating the action with [Route('yourURL')] attribute and change that accordingly in postman.