代码之家  ›  专栏  ›  技术社区  ›  bilpor

我怎么才能得到角9的圆球呢

  •  0
  • bilpor  · 技术社区  · 5 年前

    我收到以下错误:

    Access to XMLHttpRequest at 'http://localhost:40000/api/summaryCount/failed-requests' from origin
    'http://localhost:3000' has been blocked by CORS policy: 
    Response to preflight request doesn't pass access control check: 
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    

    我创建了一个proxy.conf.json文件,其中包含以下内容:

    {"/api/*": {
        "target": "http://localhost:40000",
        "secure": false
      }
    }
    

    "proxyConfig": "proxy.conf.json"
    

    在“发球”上:{“选项”{。。。。。。

    最后,我修改了package.json,使“start”选项变成:

    "start": "ng serve --proxy-config proxy.conf.json",
    

    在创建HttpHeaders对象时,如果添加以下内容:

    httpHeaders = new HttpHeaders().append('Access-Control-Allow-Origin', 'http://localhost:3000').....
    

    这仍然没有区别。

    有人能告诉我我错过了什么吗。

    2 回复  |  直到 5 年前
        1
  •  1
  •   Thierry Falvo    5 年前

    你必须启用 CORS http://localhost:3000 在您的后端服务器上 http://localhost:40000/api/... .

    角度应用程序侧无需操作。

        2
  •  0
  •   Rushi Patel    5 年前

    访问控制允许源 如果你阻止一个特定的URL,那么你也可以在那里写URL。