2017-01-10 48 views
0

我在nodejs中使用unirest發送PUT請求來更新聯繫人。從javascript更新google聯繫人的問題

unirest.put(url) 
    .header({ 
     'Authorization': 'Bearer '+result.profileData.split('?access_token=')[1], 
     'If-Match': '*', 
    }) 
    .send({"entry":{"phoneNumber":req.body.mobile}}) 
    .end(function (res1) { 
     res.send(res1); 
    }); 
} 

我得到的迴應:Object {statusCode: 415, body: "Content-Type application/x-www-form-urlencoded is not a valid input type.", headers: Object, request: Object}

我發送數據爲.send({"entry":{"phoneNumber":req.body.mobile}}),我不知道這是正確的格式?

我沒有找到任何基於JavaScript的documentation on this。幫助,將不勝感激

回答

2

它看起來像你需要提供一個內容類型標題。所以,把它添加到傳入.headers方法使用JSON的值對象/應用

... 
.headers({ 
    "Content-Type": "application/json", 
    ... 
}) 
... 
+0

它的更新,但現在設置聯繫人號碼爲空 – Satyadev

+0

不知您的錯誤信息?另外,您通常可以從您正在與之交互的API的API文檔中找到正確的請求正文格式。如果可以訪問,請閱讀API的源代碼。 – Yod

+0

API文檔非常糟糕 – Satyadev

相關問題