【问题标题】:Angular - Cannot set HttpHeader key OriginAngular - 无法设置 HttpHeader 键 Origin
【发布时间】:2020-05-08 04:42:03
【问题描述】:

我确实在 localhost 中调用 POST api。由于服务器的一些要求,我必须通过真实的 url 修改标头中的 Origin 键。但它似乎仍然显示默认的 Origin 键。我可以更改 Content-Type 但 ORigin 不是。 ;)

我的功能是:

createItem() {
    const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json',
         'Origin': 'mywebsite'
      })
    };
    const url = environment.apiUrl;
    return this.http.post(url, data, httpOptions);
}

但在 Network 选项卡中,它仍然将 Origin 值显示为 locahost

Content-Type: application/json
Origin: http://localhost:4300 // I want my url here

【问题讨论】:

    标签: angular api post header


    【解决方案1】:

    你不能:

    如 MDN 上所述; Origin 是一个“禁止”标头,这意味着您不能以编程方式更改它。

    MDN Reference Page

    Another question related to this one, with further info

    【讨论】:

    • 非常感谢。我会从服务器端询问更新
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 2017-05-08
    • 2018-03-21
    • 1970-01-01
    • 2022-09-29
    • 2016-05-11
    相关资源
    最近更新 更多