-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Send a JSON payload body in the request #1717
Comments
|
Hi, I have tested the idea, but I receive the following error:
Full code: HttpUtils.prototype.DEBUG = function(method,url,headers,qs,body,httpStatusAssert){
var resources = [
{
"sha1": "3722059cc37f7a56db064c1911f063da826cb211",
"size": 36
},
{
"sha1": "a9993e364706816aba3e25717850c26c9cd0d89d",
"size": 1
}];
var options = {
method: 'PUT',
url: url,
headers: headers,
body: {body:JSON.stringify(resources)}
};
return new Promise(function (resolve, reject) {
request(options, function (error, response, body) {
if(error){
return reject(error);
}
console.log(body);
return resolve(body);
});
});
} In what option, I have to append: {body:JSON.stringify({object})} in the request? I am using: "request": "^2.45.0" |
Nope, just |
Many thanks, it runs nice! |
Please note, this has changed and per the README section related to |
I'll add to this, since I had a similar issue. I needed to not wrap the value of "body" in options with object braces. So this was my valid code: var solution = [ {"x": 0, "y": 0}, {"x": 1, "y": 0},
{"x": 2, "y": 0},
{"x": 2, "y": 1},
{"x": 2, "y": 2},
{"x": 3, "y": 2},
{"x": 3, "y": 3}
]
var options = {
method: 'POST',
url: url,
headers: headers,
body: solution
};
rp(options)...
} |
I use nodejs http request Change It's work for me |
Hi,
I would like to know how to send this structure:
In a PUT request.
I am developing a Cloud foundry client for Node.js and I have this doubt.
http://apidocs.cloudfoundry.org/214/resource_match/list_all_matching_resources.html
I have this request:
but my question is how to add the JSON to the request.
What is the best way?
Many thanks in advance.
Juan Antonio
The text was updated successfully, but these errors were encountered: