【问题标题】:Cross-Origin Request Blocked when sending post发送帖子时阻止跨域请求
【发布时间】:2018-09-27 18:36:34
【问题描述】:

我正在使用 Angular 5 编写应用程序。

当我尝试发送请求时:

this.httpClient.post("https://api.textlocal.in/send/", new Message(this.apiKey, "xxxxxxxxx", "TEST", "SOIS_App")

我明白了:

跨域请求被阻止:同源策略不允许读取位于https://api.textlocal.in/send/ 的远程资源。 (原因:CORS 预检通道的 CORS 标头“Access-Control-Allow-Headers”中缺少令牌“access-control-allow-headers”)。

当我将请求从我的计算机发送到https://api.textlocal.in 时,如何获得 CORB??

【问题讨论】:

  • CORS 标头已添加到您的服务器上,需要在那里进行。
  • 正如我提到的:这不是我的服务器。我正在使用某人的 API
  • 正如我提到的:CORS 标头已添加到您的服务器上。控制它的人需要允许您的主机。这是基本的网络安全。
  • textlocal.com api 可能不支持吗?
  • 您需要联系 textlocal.com,您不能在您的应用程序中只使用随机 API。

标签: angular typescript


【解决方案1】:

当我从我的电脑向https://api.textlocal.in发送请求时,我如何获得CORB

在您的服务器上为地址 localhost 启用 CORS(或从您运行应用程序的任何位置)。

详细指南

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

快速指南

  1. 启用OPTIONS 端点
  2. 在您的帖子中启用标题:

Access-Control-Allow-Origin: http://foo.example Access-Control-Allow-Methods: POST Access-Control-Allow-Headers: Content-Type

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-26
    • 2014-10-13
    • 2019-11-04
    • 2017-02-06
    • 2023-03-26
    • 2013-11-03
    相关资源
    最近更新 更多