我正在使用CORS协议在Firefox中发出一个简单的POST请求。显然,一切似乎都没问题,但OPTIONS预检后请求仍被拒绝。控制台显示此错误,POST永远不会发送。
阻止跨源请求:同源策略禁止读取 远程资源在 http://127.0.0.1/project/server/rpc.php?do=init。 (原因:CORS标题 'Access-Control-Allow-Origin'与'*'不匹配。
REQUEST:
OPTIONS /project/server/rpc.php?do=init HTTP/1.1\r\n
Host: 127.0.0.1\r\n
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
Accept-Language: en-US,en;q=0.5\r\n
Accept-Encoding: gzip, deflate\r\n
Access-Control-Request-Method: POST\r\n
Access-Control-Request-Headers: x-pingother\r\n
Origin: http://localhost:3000\r\n
DNT: 1\r\n
Connection: keep-alive\r\n
\r\n
响应:
HTTP/1.1 200 OK\r\n
Date: Thu, 01 Dec 2016 12:22:57 GMT\r\n
Server: Apache/2.4.18 (Ubuntu)\r\n
Set-Cookie: PHPSESSID=nq5hf75ijfoeebale0fsd64hl7; path=/\r\n
Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n
Cache-Control: no-store, no-cache, must-revalidate\r\n
Pragma: no-cache\r\n
Set-Cookie: lang=it_IT; expires=Sat, 09-Jan-2021 12:22:57 GMT; Max-Age=129600000; path=/\r\n
Allow: OPTIONS, GET, HEAD, POST\r\n
Access-Control-Allow-Origin: *\r\n
Access-Control-Allow-Headers: x-pingother\r\n
Access-Control-Allow-Methods: OPTIONS, GET, HEAD, POST\r\n
Access-Control-Max-Age: 86400\r\n
Access-Control-Allow-Credentials: true\r\n
Content-Length: 0\r\n
Keep-Alive: timeout=5, max=100\r\n
Connection: Keep-Alive\r\n
Content-Type: text/html; charset=UTF-8\r\n
\r\n
经过几个小时的调试和实验,我仍然无法看清楚是什么问题。提前感谢您的帮助。