Mike
Mike

Reputation: 1160

Postman 400 Bad Request for web Api

I have a very basic webApi built/running (pretty much template app, nothing more) in order to follow a training video. The GET and DELETE calls work fine, PUT and POST give a 400 error. Admittedly very new to all this so I'm looking for some basic direction as to how to troubleshoot. Pertinent screen shots follow, I'd be glad to provide others as requested. Thanks in advance.

enter image description here

enter image description here

enter image description here

enter image description here

Upvotes: 2

Views: 10784

Answers (3)

VivekDev
VivekDev

Reputation: 25389

Mine is a development env on .net core.

This drove me nuts and lost 5 hours, all preventing post requests from either the browser calls or from Postman.

The following three changes helped me in 3 different scenarios.

  1. First I disabled the https and made it only http. Commented out sslPort and removed 's' from https.

launch url in application settings json file

  1. Next I felt xsrf/csrf token are causing issues, so I disabled Anti Forgery token as follows. As you can see I applied the IgnoreAntiforgeryToken attribute at the controller level, but you may also apply at the action method level as needed. The token is sent anyway, but you can ask .net core to ignore it, for that route.

Applying anti forgery token at controller level

  1. Finally, I noticed that ApiVersion parameter in the action method is also causing issues, so I commented that out as well.

ApiVersion parameter with FromRoute attribute

Upvotes: 0

Sarthak Adgaonkar
Sarthak Adgaonkar

Reputation: 1

I know this very old thread but may help someone so posting my answer. try updating your method attribute[HttpPost("New")] and call it as http:localhost//api/new.

Upvotes: 0

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

Reputation: 30565

you are trying to make POST request which needs string value in its body.

Step to the Body section of the Postman Request, select form-data after that add value as parameterName and This is test string as parameter value

enter image description here

Upvotes: 4

Related Questions