对 Url 的 post 请求给出了被 cors 策略阻止的错误

-1 cors angular

我正在尝试向 发出帖子请求,URL = "https://sambhav.daily.co/v1/rooms"但我收到了被 cors 政策阻止的错误

addRoom(): Observable<any> {
    const headers = new HttpHeaders()
      .set("content-type", "application/json")
      .set("Access-Control-Allow-Origin", "http://localhost:8000")
      .set("Access-Control-Allow-Methods", "GET,POST,PATCH,DELETE,PUT,OPTIONS")
      .set(
        "Access-Control-Allow-Headers",
        "Origin, Content-Type, X-Auth-Token, content-type"
      )
      .set(
        "Authorization",
        `Bearer <API-KEY>`
      );
    return this.http
      .post(URL, { headers: headers })
      .map((response: any) => response.data)
      .catch(this.handleError);
  }
Run Code Online (Sandbox Code Playgroud)

我收到的错误

Access to XMLHttpRequest at 'https://sambhav.daily.co/v1/rooms' from origin 'http://localhost:8000' 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.

Run Code Online (Sandbox Code Playgroud)

小智 5

来自 Daily 的 Phil 在这里。

我认为问题在于您的请求的基本 URL。所有 REST API 调用都使用https://api.daily.co/v1/

因此,在您的情况下,您想将 POST 发送到https://api.daily.co/v1/rooms.

如果文档不清楚,请告诉我。我们现在正在改造它们,您的意见很有价值。

我还建议刷新您的 API 密钥,因为您已将其包含在上面。