AngularJS和Apiary.IO - 无法读取任何响应头? [英] AngularJS and Apiary.IO - can't read any response headers?

查看:266
本文介绍了AngularJS和Apiary.IO - 无法读取任何响应头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apiary.io嘲笑我的API。但不知何故,我无法从响应对象使用angularJS读取任何头。而且我相信我至少有内容类型:应用程序/ JSON正确建立在萤火检查。在角code应该正确读取头太大,我可以发送请求到别的地方比apiary.io ...

I mocking my API using Apiary.io. But somehow I cannot read any headers from response object using angularJS. And I am sure i have at least Content-Type: application/json correctly set-up by checking in firebug. Code in Angular should read headers correctly too as i can print them when sending request to somewhere else than 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

推荐答案

这一切都归结为在Firefox中的错误:的 https://bugzilla.mozilla.org/show_bug.cgi?id=608735

It all boils down to a bug in firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=608735

有关要求CORS,Firefox是不会回来了req.getAllRequestHeaders()什么,虽然req.getRequestHeader(Content-Type的')返回正常。

For CORS request, firefox is not returning anything for req.getAllRequestHeaders(), although req.getRequestHeader('Content-Type') returns properly.

无论是FF的bug已被固定或角必须解决它(如jQuery不会),或者你必须去更深入和直接使用XmlHtt prequest实例。

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.

这是也许也有关,但可能不是核心问题:

This was maybe also related, but probably not the core issue:

不过,前几天,Apiary.io没有设置最大年龄 CORS 头。因此,如果你有一个最小的蓝图,你可能有 CORS pre-飞行响应缓存,即使你添加更多的资源,你的蓝图,因此后续的请求可能被禁止

However, few days ago, Apiary.io was not setting Max-Age in CORS headers. 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.

最大年龄现在设置为10秒,所以它应该正常工作。但是,根据您的浏览器,pre-飞行缓存仍可能影响到你。尝试清除它,或者在其他浏览器中测试这个程序。

Max-Age is now set to 10 seconds, so it should work properly. However, depending on your browser, pre-flight cache might still affect you. Try purging it or test this app in another browser.

这篇关于AngularJS和Apiary.IO - 无法读取任何响应头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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