Nodejs PUT请求与参数

我正在试图使用请求到一个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); }) 

我得到的错误:

  'Error number': 303, Error: 'Empty PUT on /data endpoint' 

有两个参数需要:id(一个数字)和bdata(JSON)。 APIpostObj将包含它们作为{“id”:33,“bdata”:{…}}。

我错过了什么?

你可以试试这个吗?

  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); }) 

你也可以试试这个。 通常和我一起工作很好。

 request({ uri: url, method: "PUT", headers: { 'Content-type': 'application/json' }, body: APIpostObj, json: true }, (error, response, body) => { // Do Stuff })