tags:

views:

3424

answers:

3

Hi,

When I try to send an HTTP GET request through XMLHttpRequest it works on non-secure HTTP.

But when sent over HTTPS, different browsers gave different results:

On Firefox 3.0.2: - The GET request doesn't reach the web server.

On IE 7: - The GET request reached the web server.

Does this have something to do with Firefox 3 getting stricter with untrusted certificates? Is there a way around this?

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.

Using both absolute and relative URL path doesn't work.

Here's the code snippet:

    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

A: 

By any chance, are you requesting a non-HTTPS URL in an HTTPS page? Do any messages appear in the error log/console?

John Millikin
I've updated the question.
ksuralta
Explicitly using HTTPS as a URL doesn't work also.No error message reported on Firefox's Error Console.
ksuralta
+1  A: 

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);

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.

Chris
A: 

do you fix the error ?? post the solutions pls...

no, i haven't found any solution to this problem yet..
ksuralta