我试图从解析云代码中访问以下端点:
https://api.dropboxapi.com/2/users/get_current_account终点详情:
我的云功能在提出请求的时候。
return Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://api.dropboxapi.com/2/users/get_current_account',
headers: {
'Authorization': 'Bearer ' + accessToken
}
});从Dropbox收到的错误:
Error in call to API function "users/get_current_account": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded". Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack"然后我尝试使用CURL:
curl -X POST https://api.dropboxapi.com/2/users/get_current_account --header "Authorization: Bearer **access_token"这起作用了,我得到了用户的数据。
基于错误,我修改了云代码:
return Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://api.dropboxapi.com/2/users/get_current_account',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + newAccessToken
}
});现在,我得到了以下错误:
Error in call to API function \"users/get_current_account\": request body: could not decode input as JSONhttpRequest中没有请求体。然后,我尝试将body设置为null和'‘。两人都犯了同样的错误。
首先,我不明白为什么dropbox需要一个没有参数的POST请求。
第二,如何解决错误。
非常感谢!
-更新
从错误中尝试了另外两种内容类型,即
'Content-Type': 'application/json;charset=utf-8'
'Content-Type': 'text/plain; charset=dropbox-cors-hack'仍然得到相同的错误:
Error in call to API function \"users/get_current_account\": request body: could not decode input as JSON发布于 2016-01-27 11:46:48
终于来了!这对我起了作用:
return Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://api.dropboxapi.com/2/users/get_current_account',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Authorization': 'Bearer ' + newAccessToken
},
body: JSON.stringify(null)
});我不得不在身体里使用JSON.stringify(null)。
下面的链接帮助我确定了解决方案:
发布于 2016-01-27 07:49:40
我没有使用Parse.Cloud.httpRequest,但它可能会发送一个默认的内容类型参数和请求体。然而,curl不为内容类型发送任何默认值,这就是为什么它可能与您一起工作的原因。
从错误消息中,我可以看到它也会接受text/plain,所以您可以尝试这样做。
'Content-Type': text/plain; charset=dropbox-cors-hack',我不知道他们为什么要使用没有传入数据的POST。
https://stackoverflow.com/questions/35031236
复制相似问题