ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript-Internet Explorer用户代理标头在HTTP调用与navigator.userAgent中有所不同

2019-11-21 12:35:40  阅读:440  来源: 互联网

标签:angularjs user-agent http-headers internet-explorer javascript


我需要获取AngularJS用于发送HTTP请求的User-Agent标头.当我使用Internet Explorer时,在Fiddler中,我看到在请求中发送的User-Agent等于:

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

但是,当我使用navigator.userAgent获取用户代理时,它将返回以下内容:

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko

我添加了< meta http-equiv =“ X-UA-Compatible” content =“ IE = edge” />标记在HTML< head>中,希望可以解决该问题,但不能解决.我还尝试了启用和禁用Intranet(在本例中为localhost)站点的兼容性视图.

背景:用户代理正通过查询字符串(以及查询字符串中的auth令牌)传递给Windows单击一次应用程序. Windows应用程序需要使用与AngularJS应用程序相同的身份验证令牌和用户代理,否则,如果用户代理不同,则HTTP API调用将导致401. Windows应用不应要求用户登录,而应使用与浏览器用户相同的身份验证上下文.

如何获取在Fiddler中观察到的实际User-Agent发送?

解决方法:

据我所知,在Internet Explorer版本9及更高版本中,在HTTP请求发送的版本和通过navigator.userAgent获得的版本之间的用户代理字符串几乎将有所不同,因为该字符串中存在所谓的功能标记(仅偶然地进行全新安装时,它们可能会短暂停留一会儿).这里解释了其背景:http://msdn.microsoft.com/en-us/library/ms537503%28v=vs.85%29.aspx

从msdn文档:

Earlier versions of Internet Explorer included feature tokens defined using the Pre-Platform and
Post-Platform keys part of the user-agent string during the HTTP negotiation process. Over time,
this lead to overly long user-agent strings, which in turn created problems for certain web servers.
Problems usually appeared when user-agent strings were longer than 256 characters. As of Internet
Explorer 9, the user-agent string no longer includes feature tokens during HTTP negotiation. Feature
tokens are included in the value returned by the userAgent property of the navigator object.
Applications that rely on the earlier behavior should be modified accordingly.

使用< meta http-equiv =“ X-UA-Compatible” content =“ IE = EmulateIE8” />设置兼容性查看模式.元标记也不会影响用户代理问题(我已经在MSIE 10和MSIE 11中对其进行了测试).

我可以想象的唯一的局部解决方案(不可靠)是从通过Java脚本获得的字符串中剥离已知特征属性,然后尝试比较这些字符串.

不幸的是,我怀疑您应该尝试为不涉及用户代理字符串比较的问题找到其他解决方案.

标签:angularjs,user-agent,http-headers,internet-explorer,javascript
来源: https://codeday.me/bug/20191121/2051809.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有