【发布时间】:2016-11-08 02:38:53
【问题描述】:
使用本机 fetch API,我有以下代码:
fetch('https://api.surveymonkey.net/v3/surveys/' + surveyId + '/responses/bulk?api_key=' + keySurveyMonkey + '&email=' + customerEmail, {
method: 'GET',
credentials: "include",
headers: {
"authorization": "Bearer xxxxxxxxxxxxxxxxxxxx"
}
})
.then((response) => {
return response.json();
})
由于某种原因,未设置标头,因此 API 抛出 401。
【问题讨论】:
-
我尝试过使用和不使用凭据:“include”
-
当我做等效卷曲时:
curl -X GET -H "Authorization: Bearer xxxxxx" https://api.surveymonkey.net/v3/surveys/85596932/responses/bulk?api_key=xxxxxxxxxx&email=test@example.com它工作 100% -
可能是 CORS 问题:stackoverflow.com/questions/34662288/…
-
尝试将您传递的
mode: 'cors'对象附加到fetch -
你的 "then"-callback 语法错误,应该是 .then(function(response) {... 见这里@987654322 @
标签: javascript api fetch