AngularJS无法POST标头

时间:2016-04-14 07:59:33

标签: angularjs google-chrome jersey

我正在尝试使用密码标题,在AngularJ中发出POST请求 我认为问题在于预检握手/ CORS

我收到以下错误 -

error

这是我的AngularJS控制器代码 -

enter image description here

这是Google Chrome的请求标题 -

enter image description here

我无法确定是否已发送标头,因为在服务器端收到空值。

2 个答案:

答案 0 :(得分:0)

你必须启用cors:

app.use(function(req, res,next) {
        res.header("Access-Control-Allow-Origin", "*");
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization");
        res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
        res.header('Content-Type', 'application/json');
        next();
    });*/

答案 1 :(得分:0)

你试过你的php文件,那是吗?:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST/GET');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

更新

当我阅读上面的错误消息时,错误似乎出现在响应中,所以我向您展示了我对服务器的请求的截图(来自我使用CORS的实时网络应用程序)在php上,你需要响应中的这些标题,请参阅我在服务器上的回复:

enter image description here

希望有所帮助,祝你好运。