Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman form-data works, but the raw equivalent doesn't

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!

like image 288
Reinier Kaper Avatar asked Jan 03 '15 23:01

Reinier Kaper


1 Answers

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 ;)

like image 76
jobwat Avatar answered Sep 23 '22 03:09

jobwat