Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly format body for post request?

I'm using a firefox pluing called restclient to simulate a post request. It doesnt' seem to be picking up any post data, but not sure if I'm formatting it properly.

using header: Content-Type: application/json and body: {"id":1234}

but not go, it's not picking up the id parameter in my php, is there some special formatting I need to set?

like image 923
Rob Avatar asked Dec 26 '22 22:12

Rob


2 Answers

okay, got it working, here is what is needed

two content types:

Content-Type: application/json
Content-Type: application/x-www-form-urlencoded

and then set your params like so in body:

param1=value1&param2=value2

Thanks for the help everyone.

like image 186
Rob Avatar answered Dec 29 '22 13:12

Rob


PHP will not parse a JSON body automatically into the $_POST superglobal. That only happens with application/x-www-form-urlencoded and multipart/form-data POST bodies. That said, you can parse the body yourself — you can access the raw POST body via the php://input pseudo-stream.

like image 45
lanzz Avatar answered Dec 29 '22 11:12

lanzz