-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
How to POST JSON data #271
How to POST JSON data #271
Comments
that's how you post JSON. using true is mainly for GET (it adds proper accept headers). we use this feature to post JSON in production so i'm quite confused that it wouldn't be working. there's even a test for it in test-body which is passing. |
Alright maybe I'm using something else wrong then, here is my actual request:
And here is my PHP test:
Which returns:
in the console. Anything stick out that I'm doing wrong? I really appreciate the input, thanks! |
Echo the request body, perhaps it's not being parsed as JSON on the PHP side and you're simply getting the JSON string instead of an object with the method field. |
var request = require('request')
, http = require('http')
;
http.createServer(function (req, res) {
console.log(req.headers)
req.on('data', function (d) {console.log(d.toString())})
req.on('end', function () {res.writeHead(200); res.end();})
}).listen(8080, function () {
request('http://localhost:8080',
{ method: 'POST'
, json: { method: "Bugzilla.time"}
},
function(error, response, data) {
console.log(data)
}
)
})
seems to work fine |
Was directing that to @EvanOman since it may not be parsing the string to JSON on his PHP server :P. So he might want to check what's in $_REQUEST. |
Hello, I am having issues posting data with your Request module. I am trying to POST JSON data to a locally running Bugzilla server. Using PHP curl works no problem but when I use the following code:
I get no data being passed on(we checked it with a script). what is the proper format for a post? On this support page I have seen people use the json map to be a True/False value and use form or body to hold the data but then I have seen even more people place the data straight into the json map. Which is the proper method? The documentation is very vague on the options so I am very confused. Help would be greatly appreciated, thanks!
The text was updated successfully, but these errors were encountered: