我是java脚本和CORS的新手,现在已经坚持了一段时间。我做了很多阅读但没有运气。客户端在浏览器(Chrome / Firefox)中运行并发出导致OPTION和PUT请求的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
OPTION回复:
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.
我将不胜感激任何帮助!
答案 0 :(得分:1)
您发送的返回码是否不等于200?
响应的HTTP状态代码不在2xx范围内
- 应用网络错误步骤。
CORS对代码2xx的限制为:http://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0