簡體   English   中英

帶參數的Nodejs PUT請求

[英]Nodejs PUT request with parameters

我正在嘗試使用對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
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM