所有事实:
我有一个使用 ajax 与外部系统通信的程序。
调用是使用 amplify.js/jq 定义的
因为我需要对 IE8 的跨域支持,所以我正在使用一个 haxe 脚本来代理我的调用,并将xhr
对象替换为它的shr
实现(SWFHttpRequest
):
这个 xhr 对象修改是这样完成的:
amplify.subscribe("request.before.ajax", function (resource, settings, ajaxSettings, xhr) {
if ($.browser.msie || !!navigator.userAgent.match(/Trident\/7\./)) {
if (resource.url.indexOf(requestConfig.apiUrl) != -1) {
var shr = new SWFHttpRequest(); // flash object adds this guy
ajaxSettings.xhr = function () {
return shr;
};
ajaxSettings.crossDomain = false;
ajaxSettings.error = function (e) {
var errorDialog = new gDialog({
title: "Error",
text: "Sorry, but there was an error in requesting information from our servers. Please contact support and provide the following information: response:"
+ e.responseText + " statusText: "
+ e.statusText + " status: "
+ e.status + " from url: " + resource.url
})
};
}
}
});
在 SSL 和 Http 上的非 ie 浏览器中一切正常(这里不足为奇)
在 IE8+ over HTTP 和 9+ over HTTPS 中一切正常
在 IE8 中,当通过 HTTPS 时,调用具有以下响应标头:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Access-Control-Allow-Methods: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Access-Control-Allow-Headers, Content-Type, Accept
X-Powered-By: ASP.NET
Date: Fri, 30 May 2014 10:40:51 GMT
Content-Length: 283
{"ResponseCode":200,"ResponseDescription":"OK","ResponseEntity":"P4w0uZrc2BMOjdLBYF1K2RT9Ku/rTAqDK/2st76YdwhaqGZB/Yw2QCC03ncZJXqDdGYRyty+EDmOwx9MYgZdAtUdfmygjZrD0ST8G/qc4Iwbp7I/r+X5PPbI1QNoiy1VOe7WNgXt7g12UKpRKzXhWvGCUOItA8z1VrsBXLxUtd6p45SmOjrIycKWBVRLPP37cXokvO+uiGuur1p7wF392Q=="}
这是正确的回应,我应该成功并继续前进,而是ajaxSettings.error
告诉我:
response:null
statusText: Not Found
status: 404
from url: the correct endpoint url with correct matching protocol
我不知道该怎么想或去哪里看,真的很困惑,所以任何帮助或线索都会非常感激。
如果您认为我应该在此处添加任何其他相关详细信息,请告诉我。
到目前为止我的线索和想法:
- 这可能与 IE8 JSON.parse 错误有关吗?
- 如果是在 https 上会出现这个问题吗?
- 这与通常的错误序列化 json 问题没有任何关系,因为服务器响应是正确形成的。
显然,Microsoft.XMLDOM 的 SSL 存在一些问题
所以我想也许我还包括 haxe 脚本中引用的部分:
public function onData( data:String ) {
if (!this.active) return;
var stringified = haxe.Json.stringify(haxe.Json.parse(data));
var striginiedEscaped = StringTools.replace(stringified, "\\", "\\\\");
ExternalInterface.call( [ "(function(instance, data){",
"var shr = window.SWFHttpRequest.instances[instance];",
"if (!shr) return;",
"shr.status = 200;",
"shr.statusText = 'OK';",
"shr.readyState = 4;",
"shr.responseText = data;",
"try {",
"if (window.DOMParser) {",
"var dp = new DOMParser();",
"shr.responseXML = dp.parseFromString( data, 'text/xml' );",
"} else {",
"shr.responseXML = new ActiveXObject('Microsoft.XMLDOM');",
"shr.responseXML.async = 'false';",
"shr.responseXML.loadXML(data);",
"}",
"} catch(error) { shr.responseXML = null; }",
"if (shr.onreadystatechange && typeof shr.onreadystatechange=='function') shr.onreadystatechange();",
"})" ].join(''), this.instance, striginiedEscaped);
}
根据此页面Microsoft.XMLDOM 存在 SSL 问题,我应该确保:
- 在 Internet Explorer 的“工具”菜单上,单击“Internet 选项”。在高级选项卡上,清除不将加密页面保存到磁盘复选框。
- 确保服务器不发送无缓存标头。
- 在 IIS 的 Microsoft 管理控制台 (MMC) 管理单元中,右键单击 XML 文件。在 HTTP Headers 选项卡上,关闭 Content-Expiration 选项。
以前有人处理过这个问题吗?将应用这些并报告回来。