如何使XMLHtt prequest工作通过HTTPS在Firefox? [英] How to make XMLHttpRequest work over HTTPS on Firefox?
问题描述
当我尝试发送通过XMLHtt $ P $ HTTP GET请求pquest它适用于非安全的HTTP。
When I try to send an HTTP GET request through XMLHttpRequest it works on non-secure HTTP.
但是,当通过HTTPS发送,不同的浏览器给了不同的结果:
But when sent over HTTPS, different browsers gave different results:
在Firefox 3.0.2: - 该GET请求不到达Web服务器
On Firefox 3.0.2: - The GET request doesn't reach the web server.
在IE 7: - GET请求到达Web服务器
On IE 7: - The GET request reached the web server.
这是否有东西做与Firefox 3的越来越严格与不受信任的证书? 有没有解决的办法吗?
Does this have something to do with Firefox 3 getting stricter with untrusted certificates? Is there a way around this?
我已经添加了URL作为Firefox的证书管理器异常。 错误控制台不报告任何错误。 我已经添加了各地XMLHtt prequest的open(),并发送一个try-catch。无异常。
I've already added the URL as an exception in Firefox's Certificate Manager. The error console doesn't report any error. I've added a try-catch around XMLHttpRequest's open() and send. No exception is thrown.
使用绝对和相对URL路径是行不通的。
Using both absolute and relative URL path doesn't work.
这里的code片断:
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
return false;
}
}
}
// we won't be handling any HTTP response
xmlHttp.onreadystatechange=function()
{
// do nothing..
}
// send HTTP GET request
try
{
xmlHttp.open("GET", "/[relative path to request]", true);
xmlHttp.send(null);
}
catch (e)
{
alert('Error sending HTTP GET request!');
return false;
}
谢谢, 肯尼斯·
Thanks, Kenneth
推荐答案
尝试把你关闭后开放的:
Try placing your closure after the open:
// send HTTP GET request
try
{
xmlHttp.open("GET", "/[relative path to request]", true);
}
catch (e)
{
alert('Error sending HTTP GET request!');
return false;
}
// we won't be handling any HTTP response
xmlHttp.onreadystatechange=function()
{
// do nothing..
}
// Then send it.
xmlHttp.send(null);
一个小谷歌搜索发现确认: http://www.ghastlyfop.com/blog/2007 /01/onreadystate-changes-in-firefox.html
A little googling found confirmation: http://www.ghastlyfop.com/blog/2007/01/onreadystate-changes-in-firefox.html
虽然该文件说,附加后。发送(空)的功能,我已经 始终高度后打开。
Although that document says to attach the function after .send(null), I've always attached after open.
这篇关于如何使XMLHtt prequest工作通过HTTPS在Firefox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!