[英]Nodejs PUT request with parameters
I'm trying to make a PUT request using request to a url: 我正在尝试使用对URL的请求来发出PUT请求:
request({
uri: 'http://apiurl.url/1.0/data?token=' + APItoken,
method: 'PUT',
data: [{
'content-type': 'application/json',
body: JSON.stringify(APIpostObj)
}],
json: true
},
function(error, response, body) {
if (error) {
return console.error('upload failed:', error);
}
console.log('Server responded with:', body);
})
I get the error: 我得到错误:
'Error number': 303, Error: 'Empty PUT on /data endpoint'
There are two parameters required: id (a number) and bdata (JSON). 需要两个参数:id(一个数字)和bdata(JSON)。 The APIpostObj would contain them as {"id":33, "bdata":{...}}.
APIpostObj会将它们包含为{“ id”:33,“ bdata”:{...}}。
What am I missing? 我想念什么?
Can you try this 你可以试试这个吗
request({
uri: 'http://apiurl.url/1.0/data?token=' + APItoken,
method: 'PUT',
json: [{
'content-type': 'application/json',
body: JSON.stringify(APIpostObj)
}]
},
function(error, response, body) {
if (error) {
return console.error('upload failed:', error);
}
console.log('Server responded with:', body);
})
You could also try this. 您也可以尝试一下。 Usually works fine with me.
通常可以和我一起工作。
request({
uri: url,
method: "PUT",
headers: {
'Content-type': 'application/json'
},
body: APIpostObj,
json: true
}, (error, response, body) => {
// Do Stuff
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.