【问题标题】:Nodejs PUT request with parameters带参数的Nodejs PUT请求
【发布时间】:2017-11-18 03:47:40
【问题描述】:

我正在尝试使用对 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":{...}}。

我错过了什么?

【问题讨论】:

  • 嗨,克里斯蒂安,它对你有用吗?

标签: javascript jquery node.js post request


【解决方案1】:

你也可以试试这个。通常对我很好。

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

【讨论】:

    【解决方案2】:

    你可以试试这个

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

    【讨论】:

      猜你喜欢
      • 2023-02-03
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      • 2011-11-03
      相关资源
      最近更新 更多