I'm trying to make a PUT request using request to a url:
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). The APIpostObj would contain them as {"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
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.