Vscode-restclient: req.body is empty using REST Client, but with Postman, it works fine

Created on 31 Aug 2018  路  9Comments  路  Source: Huachao/vscode-restclient

  • VSCode Version: 1.26.1
  • OS Version: Windows 10
  • REST Client Version: 0.19.1

Steps to Reproduce:

  1. Create a POST Json content
  2. Post it

When I post with REST Client, in the express route, req.body is always empty. When I post the exact same message using Postman, the express route works fine as req.body is populated as expected.

Here is the text in Rest client...
NOTE: The appSecret is 412 characters long so I clipped...

POST http://localhost:3000/message HTTP/1.1

Content-Type: application/json
{ 
    "processHandle": "joe", 
    "appSecret": "dbc339a42526a898b76eee100a1a913c2fd0dac83b663bbb72..........", 
    "tags": "test-tag,blah-tag", 
    "data": "{ \"AnObject\": { \"Attrib\": \"SubObjData...\" }, \"FirstNumber\": 27, \"ThisIsData\": \"SomeData\", \"test\": \"Hello!\", \"LastNumber\": 42 }"
}

Most helpful comment

I am experiencing the same issue where the body is not recognized.
Content-Type: "application/json"

but when I removed the quotes for application json it worked
Content-Type: application/json

All 9 comments

The blank line should exist between request body and headers, not the request line and headers

That was it. Thank you for super fast reply :-)

Same thing is happening to me with this :C

`POST http://localhost:7000/accountsmod/accounts HTTP/1.1
Content-Type: : application/json

{
"nickname": "El Juanzo",
"password": "adwfawd",
"status": true,
"role": "5f018c5afda9715ff8403736",
"user": "5f0187ae32a664164809ac4a"
}`

what could be the mistake?

@DefaultJARR could you please show me the complete http file?

I am experiencing the same issue where the body is not recognized.
Content-Type: "application/json"

but when I removed the quotes for application json it worked
Content-Type: application/json

@DefaultJARR
Hi, I noticed that there are two colons after your Content-Type which causes the client to send an invalid type and the server to not know how to process the body.

Having the same issue on Windows 10 when running requests against localhost, maybe it's related?

example.rest as follows:

POST http://127.0.0.1:8000/users HTTP/1.1
content-type: "application/json"

{
    "name": "Joao",
    "lname": "da Silva",
    "email": "[email protected]",
    "phone": "(11) 555-1234"
}

EDIT: I should mention that I'm working with VSCode 1.47.3, REST Client Version: 0.24.1 PHP 7.4.3

@andrechalom Check out @stevenson's comment above. The value of content-type should not be wrapped in double quotes.

My bad, the actual problem was how I was trying to read the $_POST superglobal, when I should be looking at file_get_contents("php://input")

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wboyle-erwin picture wboyle-erwin  路  43Comments

agjs picture agjs  路  31Comments

Odonno picture Odonno  路  22Comments

olivier-voutat picture olivier-voutat  路  23Comments

codepunkt picture codepunkt  路  29Comments