飞行前响应中Access-Control-Allow-Headers不允许请求标头字段Pragma [英] Request header field Pragma is not allowed by Access-Control-Allow-Headers in preflight response

查看:123
本文介绍了飞行前响应中Access-Control-Allow-Headers不允许请求标头字段Pragma的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试保留以下代码以禁用Ajax缓存时出现此错误

I am getting this error when I was trying to keep the following code to disable cache for ajax

angularApp.config(['appConfig', '$httpProvider', function (appConfig, $httpProvider) {

if (!$httpProvider.defaults.headers.get) {
    $httpProvider.defaults.headers.get = {};
}

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

}]);

我在chrome中遇到错误,如下所示:

I am getting error in chrome as follows:

在飞行前响应中,Access-Control-Allow-Headers不允许请求标头字段Pragma.

Request header field Pragma is not allowed by Access-Control-Allow-Headers in preflight response.

但是当我删除以下代码时,它的工作正常.

But when I remove the following code, its working fine.

$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

有人可以告诉我可能是什么问题吗?

can any one tell me what could be the problem?

推荐答案

如果可以在服务器端进行配置以接受这些标头,则可以.否则,您应该删除那些在$ httpProvider.defaulsts中设置的标头.检查以下代码:

If you can configure in server side to accept those headers, then it's fine. Else, you should remove those header which is set in $httpProvider.defaulsts. Check the code below:

var data = {}
var httpCoonfig = {
    headers: {'Pragma': undefined, 'Cache-Control': undefined, 'X-Requested-With': undefined, 'If-Modified-Since': undefined}
};
$http.post('https://www.google.com/', data, httpCoonfig).then(function(response){
// console.log(response)
}, function(response){
     console.log(response)
});

这篇关于飞行前响应中Access-Control-Allow-Headers不允许请求标头字段Pragma的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆