gpt4 book ai didi

java - 服务器返回 CORS header ,浏览器仍然抛出 Cross-Origin Request Blocked 错误

转载 作者:行者123 更新时间:2023-11-30 08:17:10 26 4
gpt4 key购买 nike

我是 java 脚本和 CORS 的新手,并且已经被这个问题困扰了一段时间。我读了很多书,但没有运气。客户端在浏览器 (Chrome/Firefox) 中运行并发出 PUT 请求,这会导致 OPTION 和 PUT 请求。服务器正在将 PUT 请求重定向到另一台服务器。以下是基于java脚本的客户端和基于java的服务器之间的HTTP通信捕获:

选项请求:

Host: 10.232.65.230:8000
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://10.232.65.230:3001
Access-Control-Request-Method: PUT
Connection: keep-alive

选项响应:

Status Code: 200
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Methods: PUT
Access-Control-Allow-Origin: http://10.232.65.230:3001
Access-Control-Max-Age: 1800
Cache-Control: private
Content-Length: 0
Date: Tue, 07 Apr 2015 13:48:50 GMT
Expires: Thu, 01 Jan 1970 05:30:00 IST
Server: Apache-Coyote/1.1

PUT 请求:

Host: 10.232.65.230:8000
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://10.232.65.230:3001/ermsim/erms/1/edgedevices
Content-Length: 159
Content-Type: text/plain; charset=UTF-8
Origin: http://10.232.65.230:3001
Connection: keep-alive

PUT 响应:

Status Code: 302
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Methods: PUT
Access-Control-Allow-Origin: http://10.232.65.230:3001
Cache-Control: private
Content-Length: 0
Content-Type: application/xml
Date: Tue, 07 Apr 2015 13:48:50 GMT
Expires: Thu, 01 Jan 1970 05:30:00 IST
Location: http://10.232.65.230:8000/edge/ermsim/erms/1/edgedevices/1/config/edgeinputs/1
Server: Apache-Coyote/1.1

但是,浏览器没有重定向到提供的位置,而是抛出以下错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://10.232.65.230:8000/ermsim/erms/1/edgedevices/1/config/edgeinputs/1. This can be fixed by moving the resource to the same domain or enabling CORS.

如果有任何帮助,我将不胜感激!

最佳答案

您发送的返回码是否不等于 200?

The response has an HTTP status code that is not in the 2xx range

  • Apply the network error steps.

CORS 对代码 2xx 有限制:http://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0

关于java - 服务器返回 CORS header ,浏览器仍然抛出 Cross-Origin Request Blocked 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29497437/

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