【问题标题】:angular 4 httpGet withCredentials and header conflictangular 4 httpGet withCredentials 和标头冲突
【发布时间】:2018-07-28 01:55:15
【问题描述】:

为了向服务器发送 cookie,我必须在 options 参数中使用 { withCredentials: true },但是当我使用时

    this.http.get(this.accountUrl + 'ExternalLoginConfirmation', { 
    withCredentials: true })

我收到以下错误:

    Response to preflight request doesn't pass access control check: The 
    value 
    of the 'Access-Control-Allow-Origin' header in the response must not be 
    the 
    wildcard '*' when the request's credentials mode is 'include'. Origin 
    'http://localhost:4202' is therefore not allowed access. The credentials 
    mode of requests initiated by the XMLHttpRequest is controlled by the 
    withCredentials attribute.

奇怪的是:当我通过浏览器调用此 url 时没有任何错误

你能帮帮我吗?

【问题讨论】:

    标签: angular angular4-httpclient


    【解决方案1】:

    这是一个 CORS 错误, 尝试添加 Cors chrome 扩展浏览器并在其中添加您的网址,此错误将消失。 或永久解决 参考https://stackoverflow.com/a/24446980/4808975

    【讨论】:

    • 谢谢!它适用于服务器端的builder.AllowAnyOrigin() .AllowAnyMethod().AllowAnyHeader().AllowCredentials();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-19
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 2017-12-08
    相关资源
    最近更新 更多