我的后端服务器是grpc服务器(由Golang写),Envoy用于反向代理,它在端口:8080上运行具有配置cors:cors:
allow_origin_string_match:
- safe_regex:
google_re2: {}
regex: \*
allow_methods: GET, PUT, DELETE, POST, OPTIONS, PATCH
allow_headers: authorization, keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
max_age: "1728000"
expose_headers: custom-header-1,grpc-status,grpc-message
在前端,我使用React库Axios调用服务器的API。被浏览器阻止,并显示以下错误:
Access to XMLHttpRequest at 'http://localhost:8080/api/books/d23ea317-e667-449c-a77d-495859e37d30/bookfiles' from origin 'http://localhost:5000' 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.
浏览器阻止或使节配置有什么问题?
最佳答案
http。服务器必须响应标头在cors中具有Access-Control-Allow-Origin
,Access-Control-Allow-Origin
值需要是请求Origin
标头值或const值,相对而言,新的浏览器不支持Access-Control-Allow-Origin
标头值为*
您在chrome网络中检查响应标头。
关于go - 在React Web中使用Axios的Access Control Origin Header错误在Chrome和后端中使用Envoy进行反向代理抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61138453/