Firefox中的跨域XHR到https地址(SSL)失败(在Chrome中运行) [英] Cross-domain XHR to https address (SSL) fails in Firefox (works in Chrome)

查看:560
本文介绍了Firefox中的跨域XHR到https地址(SSL)失败(在Chrome中运行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用下面的代码来实现这一点:$ b​​
$ b

  this.post = function(url,data){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open(POST,url,true);
xmlhttp.withCredentials = true;
xmlhttp.setRequestHeader(Content-type,application / x-www-form-urlencoded; charset = UTF-8);
xmlhttp.send(data);



$ b我使用这个函数与url编码的字符串数据和 https://mydomainx.com/request 作为url。



我在Chrome和Firefox上用Chrome Dev Tools / Firebug看着请求/响应标题)。该代码适用于Chrome(即发送请求,收到适当的响应)。
不安全的请求在Firefox上工作(当我使用 http://mydomainx.com/request 而不是https)。



更具体地说,在Firefox上,似乎发送了https请求:POST请求出现在Firebug中,请求标题正确,但是没有收到响应。我检查了端点服务器(mydomainx.com),它没有收到请求(说/var/log/apache2/access.log和error.log)。当xhr.readystate == 4 ----> status = 0,没有响应文本时,我也显示了status / responseText。



我试着做XHR没有数据,与GET而不是POST,没有内容头,和一个文本/纯文本内容标题=>完全相同的结果(在http / https中的铬,工作在Firefox与firefox,不工作在Firefox与Firefox)。 / p>

我花了很多时间试图谷歌解释没有成功...任何帮助将不胜感激。
非常感谢

解决方案

您是否尝试过在Firefox标签中访问URL的安全版本?这听起来像Firefox可能会卡在SSL证书,并可能希望你添加一个例外接受证书之前XHR请求到该URL将工作。


I'm trying to make a cross-domain XHR to a secure domain.

I used the following code to do so:

this.post = function (url, data) {
    var xmlhttp=new XMLHttpRequest();
    xmlhttp.open("POST",url,true);
    xmlhttp.withCredentials=true;
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlhttp.send(data);
}

I use this function with url-encoded string data and https://mydomainx.com/request as url.

I tested it on Chrome and Firefox, with Chrome Dev Tools / Firebug (looking at requests/response headers). The code works on Chrome (i.e. request sent, appropriate response received). The unsecure request works on Firefox though (when I use http://mydomainx.com/request rather than https).

More specifically, on Firefox, the https request seems to be sent: the POST request appears in Firebug with correct request headers, but no response is received. I checked on the endpoint server (mydomainx.com), it does not receive the request (says /var/log/apache2/access.log and error.log). I also displayed status / responseText when xhr.readystate == 4 ----> status = 0, no response text.

I tried making the XHR without data, or with GET instead of POST, and without the content header, and with a text/plain content header => exact same results (works on chrome in http/https, works on firefox with http, does not work on firefox with https).

I spent a lot of time trying to google for an explanation with no success... Any help will be greatly appreciated. Thanks a lot

解决方案

Have you tried accessing the secure version of the URL in a Firefox tab? It sounds like Firefox may be getting stuck on the SSL certificate and may want you to add an exception to accept the certificate before XHR requests to that URL will work.

这篇关于Firefox中的跨域XHR到https地址(SSL)失败(在Chrome中运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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