浏览器块请求CORS

时间:2015-01-11 14:38:21

标签: php apache cross-browser network-programming

我希望从hostA(192.168.10.16)向hostB发送请求(publicIP:91.241.22.2,localIP:192.168.10.5

我用这个

设置了Apache(91.241.22.2)
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"

PHP

header("Access-Control-Allow-Origin: *");

向publicIP发送请求时:91.241.22.2这有效。

但是,但是

向localIP发送请求时:192.168.10.5 Firefox说错误:跨源请求被阻止:同源策略不允许在192.168.10.5/shemareSafhe.php读取远程资源。这可以通过将资源移动到同一域或启用CORS来解决。

请帮助我:(

1 个答案:

答案 0 :(得分:0)

使用浏览器或shell检查标题

curl -i 'http://192.168.10.5/shemareSafhe.php'
curl -i 'http://91.241.22.2/shemareSafhe.php'

检查区别,我更喜欢只用PHP设置标题