我已使用以下代码
将令牌设置为我的请求的标头$http.defaults.headers.common['X-Auth-Token'] = 'mytoken';
我的firebug中显示的请求标题如下。
X-Auth-Token mytoken
X-Powered-By PHP/5.5.9-1ubuntu4.13
access-control-allow-orig... *
在我的服务器端代码中,我添加了以下行
header("Access-Control-Allow-Origin: *");
header("x-auth-token: mytoken");
我仍然收到以下错误
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/app/item/get. (Reason: missing token 'x-auth-token' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel).
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/app/item/get. (Reason: CORS request failed).
如果我删除下面的标记标题,一切正常
$http.defaults.headers.common['X-Auth-Token'] = 'mytoken';