简体   繁体   English

AngularJS:缺少标头的http请求

[英]AngularJS: http request with missing headers

I am doing a request in this way using AngularJS: 我正在使用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) { });

The request is fired, but when I check on Firefox (Firebug) the request is missing of the Authorization/Content-Type headers I have set and it returns a "200 OPTIONS REQUEST" that is related to CORS. 该请求被触发,但是当我在Firefox(Firebug)上检查时,该请求缺少我设置的Authorization / Content-Type标头,它返回与CORS相关的“ 200 OPTIONS REQUEST”。 Anyway I am wondering if the issue is really related to CORS or missing headers and in a case or another what is the solution. 无论如何,我想知道问题是否真的与CORS或标题丢失有关,或者在某种情况下,解决方案是什么。

I can suggest you the solution for the cors, but it is server side. 我可以为您建议cors解决方案,但这是服务器端的解决方案。 you need to write some attribute in the headers. 您需要在标题中写一些属性。 To be precise this ones 确切地说,
Host="the host from you have called the get" Host =“来自您的主机已调用get”
Origin="the origin domain of your request" Origin =“您的请求的来源域”
Referer="the orgin domain + the page" Referer =“原始域+页面”

and in the request you have to add this 并且在请求中您必须添加此
access-control-allow-credentials=true 访问控制允许的凭据=真
and i think it's related to the cors, i had your same problem. 而且我认为这与cors有关,我也遇到了同样的问题。 If it persist after you had handle the cors, clean the browser cache. 如果在处理完问题后仍然存在,请清理浏览器缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM