简体   繁体   English

AngularJS和Apiary.IO - 无法读取任何响应标头?

[英]AngularJS and Apiary.IO - can't read any response headers?

I mocking my API using Apiary.io. 我使用Apiary.io模拟我的API。 But somehow I cannot read any headers from response object using angularJS. 但不知怎的,我无法使用angularJS从响应对象中读取任何标头。 And I am sure i have at least Content-Type: application/json correctly set-up by checking in firebug. 而且我确信我至少通过检查firebug来正确设置Content-Type:application / json。 Code in Angular should read headers correctly too as i can print them when sending request to somewhere else than apiary.io... Angular中的代码也应正确读取标题,因为我可以在向apiary.io发送请求时将其打印出来...

  $http.get('http://ies.apiary.io/some').then(function(response) {  
    console.log("ok",response.headers('Content-Type'));
    },function(response){console.log("err",response);});

http://plnkr.co/edit/zMO0pXGsIdJkV0fZdBdw http://plnkr.co/edit/zMO0pXGsIdJkV0fZdBdw

It all boils down to a bug in firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=608735 这一切都归结为firefox中的一个错误: https//bugzilla.mozilla.org/show_bug.cgi? id = 608735

For CORS request, firefox is not returning anything for req.getAllRequestHeaders(), although req.getRequestHeader('Content-Type') returns properly. 对于CORS请求,firefox没有为req.getAllRequestHeaders()返回任何内容,尽管req.getRequestHeader('Content-Type')正确返回。

Either FF bug has to be fixed or Angular must work around it (as jQuery does) or you must go deeper and use XmlHttpRequest instance directly. 要么必须修复FF bug,要么Angular必须解决它(就像jQuery那样)或者你必须更深入并直接使用XmlHttpRequest实例。


This was maybe also related, but probably not the core issue: 这可能也是相关的,但可能不是核心问题:


However, few days ago, Apiary.io was not setting Max-Age in CORS headers. 然而,几天前,Apiary.io没有在CORS标题中设置Max-Age Thus, if you had a minimal blueprint, you might have CORS pre-flight response cached and thus subsequent requests may be disallowed even if you added additional resources to your blueprint. 因此,如果您有最小的蓝图,则可能会缓存CORS飞行前响应,因此即使您向蓝图添加了其他资源,也可能不允许后续请求。

Max-Age is now set to 10 seconds, so it should work properly. Max-Age现在设置为10秒,因此它应该正常工作。 However, depending on your browser, pre-flight cache might still affect you. 但是,根据您的浏览器,飞行前缓存可能仍然会影响您。 Try purging it or test this app in another browser. 尝试清除它或在另一个浏览器中测试此应用程序。

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

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