Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS:缺少标头的http请求_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS:缺少标头的http请求

Javascript AngularJS:缺少标头的http请求,javascript,angularjs,Javascript,Angularjs,我使用AngularJS以这种方式执行请求: var config = { headers: { 'Authorization': 'somehash', 'Content-Type': 'application/json; charset=UTF-8' } }; $http.get('http://example.com', config) .then(function(response) {

我使用AngularJS以这种方式执行请求:

    var config = { headers: {
            'Authorization': 'somehash',
            'Content-Type': 'application/json; charset=UTF-8'
    } };

    $http.get('http://example.com', config)
        .then(function(response) { 
            $scope.response = response;
    }, function(response) { });

请求被触发,但当我在Firefox(Firebug)上检查时,请求缺少我设置的授权/内容类型头,它返回一个与CORS相关的“200选项请求”。无论如何,我想知道问题是否真的与CORS或缺少标题有关,在某种情况下,解决方案是什么。

我可以向您建议CORS的解决方案,但它是服务器端的。您需要在标题中写入一些属性。准确地说,这是一个
Host=“您的主机已调用get”
Origin=“您请求的源域”
Referer=“原始域+页面”

在请求中,您必须添加此
访问控制允许凭据=true

我想这和cors有关,我也有你的问题。如果在处理cors后它仍然存在,请清理浏览器缓存。

必须在选项1之后发送GET请求:此请求是否具有提供的标头?