gpt4 book ai didi

javascript - "No ' 访问控制允许来源 ' header is present on the requested resource.The response had HTTP status code 403."

转载 作者:太空狗 更新时间:2023-10-29 18:24:41 25 4
gpt4 key购买 nike

我有 Angular 产品服务及其使用 HttpClient 方法调用“http://jsonplaceholder.typicode.com/posts”的 URL。

但是,它显示“请求的资源上不存在‘Access-Control-Allow-Origin’ header 。因此不允许访问来源‘http://localhost:5700’。响应的 HTTP 状态代码为 403。”

根据我对上述错误的理解,错误是需要设置 header ,但它只是公共(public)获取 API,所以我认为不需要为此设置 header 。

提前致谢。

最佳答案

实际上是浏览器抛出的错误,只能在服务器端修复。如您所见,端点未在响应 header 中设置 Access-Control-Allow-Origin,因此您无法从浏览器内的任何其他域调用它(在本例中, 'http://localhost:5700)。它的标题是:

access-control-allow-credentials →true
cache-control →public, max-age=14400
cf-cache-status →HIT
cf-ray →3c4f9790845896e8-FRA
connection →keep-alive
content-encoding →gzip
content-type →application/json; charset=utf-8
date →Tue, 28 Nov 2017 19:04:16 GMT
etag →W/"6b80-Ybsq/K6GwwqrYkAsFxqDXGC7DoM"
expires →Tue, 28 Nov 2017 23:04:16 GMT
pragma →no-cache
server →cloudflare-nginx
transfer-encoding →chunked
vary →Accept-Encoding
via →1.1 vegur
x-content-type-options →nosniff
x-powered-by →Express

关于javascript - "No ' 访问控制允许来源 ' header is present on the requested resource.The response had HTTP status code 403.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47538991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com