Postman form-data works, but the raw equivalent doesn't
Solution 1
Ensure your Content-Type
header!
If your raw data is JSON: Content-Type: application/json
I experienced a similar issue to yours: my request was working using the form-data, but not as raw... and after debugging the request server side, I realised my request Content-Type was "text/plain;charset=UTF-8"
.. even if JSON was selected in the side dropdown...
Hope it saves time to the next one ;)
Solution 2
Okay I found it.
Apparently the "comment[response]" is actually:
{"comment":{"response": "something"}}
in JSON.
Learned something :)
Solution 3
Select raw option with JSON(application/json).
Reinier Kaper
Updated on July 30, 2022Comments
-
Reinier Kaper almost 2 years
I have an API that I'm testing with and if I submit my data through "form-data" with the following values it works:
key: response[comment] value: This is a test
But if I do some custom JSON in the "raw" tab with the following structure, it doesn't work:
{ "response[comment]": "This is a test" }
It's driving me nuts to be honest as the server doesn't give me any details on what's wrong. I have the feeling it's the encoding of the object that goes wrong, but I'm using Angular and I get the same 400 error, while I'm fairly sure it should just work with a JS object as the data on a .post.
Any help would be appreciated!
-
Admin over 2 yearsPlease add further details to expand on your answer, such as working code or documentation citations.