【问题标题】:Headers not set on fetch api call未在 fetch api 调用上设置标头
【发布时间】: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%
  • 尝试将您传递的mode: 'cors' 对象附加到fetch
  • 你的 "then"-callback 语法错误,应该是 .then(function(response) {... 见这里@987654322 @

标签: javascript api fetch


【解决方案1】:

事实证明,SurveyMonkey 最近进行了一些基础架构更改,导致 CORS 标头无法发送。我相信这是暂时的情况。

【讨论】:

    【解决方案2】:

    我从 4 号星期五开始遇到同样的问题。 它在 Postman 中运行良好,但在我的 Web 应用程序中无法运行。

    我尝试使用 Fiddler 来查看差异和...魔术...使用 Fiddler 4:效果很好!没有变化,只需使用 Fiddler 即可...

    这是什么意思? Fiddler 是否也做了我们需要做的事情?

    感谢您的建议。

    【讨论】:

    • SurveyMonkey 团队正在努力解决这个问题。希望尽快解决。
    • 请告诉我们“很快”是什么意思?
    • 我可以确认他们已经修复了它。我已经测试过了,API 现在又支持 CORS 头了。
    • 我还是有同样的问题!
    • 当您从浏览器运行此程序时,您在“网络”选项卡中返回的确切消息是什么?
    猜你喜欢
    • 2018-01-14
    • 2019-01-22
    • 2017-09-03
    • 2022-10-04
    • 1970-01-01
    • 2017-10-03
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多