Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP will not receive correctly when set option "json" to "true" #2111

Closed
wilsoncook opened this issue Mar 4, 2016 · 4 comments
Closed

PHP will not receive correctly when set option "json" to "true" #2111

wilsoncook opened this issue Mar 4, 2016 · 4 comments
Labels

Comments

@wilsoncook
Copy link

see this request:

request({
    url:'http://localhost/test.php', 
    method:'post',
    form:{UserId:60,title:'test1',messsage:'test1'},
    json:true, 
    proxy: 'http://127.0.0.1:8888'
}, function(err, res, body){console.log(body);});

the raw header & content will be:
image
so the body content was wrapped by double quotes, and then the php side will receive like this:
image
anyway, the content-type will not set as "application/json" like the README said.
i wondered why adding double quotes, thanks!

@IvanGaravito
Copy link

@mikeal
Copy link
Member

mikeal commented Feb 14, 2017

You're using two features at the same time that conflict with each other :)

The form option is for sending form encoded bodies. The json option if for json bodies AND for setting headers to receive JSON content types.

you should do this instead:

request.post({json: {UserId:60,title:'test1',messsage:'test1'}}, (err, resp, body) => console.log(body))

@lbossle
Copy link

lbossle commented Aug 19, 2018

@wilsoncook did @mikeal's answer solve your problem? If it did, I believe this issue should be closed.

@stale
Copy link

stale bot commented Aug 19, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 19, 2019
@stale stale bot closed this as completed Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants