【问题标题】:set withCredentials to the new ES6 built-in HTTP request API : Fetch将 withCredentials 设置为新的 ES6 内置 HTTP 请求 API:Fetch
【发布时间】:2017-03-25 09:53:25
【问题描述】:

如何将withCredentials=true 设置为返回承诺的fetch。 以下是否正确:

fetch(url,{
   method:'post',
   headers,
   withCredentials: true
});

我认为MDN documentation 谈到了关于 http 请求的所有内容,除了这一点:withCredentials

【问题讨论】:

    标签: javascript ecmascript-6 xmlhttprequest fetch-api


    【解决方案1】:

    知道了here

      credentials: 'include'
    

    而不是

      withCredentials: true
    

    【讨论】:

    • official spec 中也有一个 XHR 示例
    • 任何人在添加此配置以获取并在登录后仍未收到发送的请求 cookie 时遇到问题?
    • 也可能需要在服务器响应中添加标头'Access-Control-Allow-Credentials': true
    猜你喜欢
    • 2019-12-04
    • 1970-01-01
    • 2012-04-07
    • 2016-09-28
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多