Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress SSL error when AJAX request to the server with invalid certificate

I have this code:

function newXMLHttpRequest() {
    var xmlHttp;
    try {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (f) {
            xmlHttp = new XMLHttpRequest();
        }
    }
    return xmlHttp;
}
var xmlHttp = newXMLHttpRequest();
xmlHttp.open("POST", url, true);
xmlHttp.onreadystatechange = function() {
    // this I have xmlHttp.status = 12019        
    alert("readyState = " + xmlHttp.readyState + "\nstatus = " + xmlHttp.status);
}
xmlHttp.send('same data');

When I send request to the server with invalid certificate I have error with status code 12019.

Solution should be cross-browser (IE, FF, Chrome)

like image 781
belykh Avatar asked Nov 14 '22 07:11

belykh


1 Answers

First, to answer the question in the title, this cannot be done. The client xmlHttp libraries do not allow the client to ignore ssl errors. The MsXml2.ServerXMLHTTP object does allow one to ignore SSL errors with the setOption(2, 13056) method. However, this object cannot be used within a browser, nor is it cross-platform.

That said, there seems to be another issue. The 12019 status does not indicate an invalid certification. Some variant of an HTTP 403 status code, or one of the many 'invalid certification' codes would be expected in that case.

Your 12019 status code indicates:

ERROR_INTERNET_INCORRECT_HANDLE_STATE

12019

The requested operation cannot be carried out because the handle supplied is not in the correct state.

Unfortunately this status code doesn't really communicate much, and without knowing what versions of IE, and details about the server there's not much more to go on. I've checked a number of forum posts. One stated switching to IIS fixed the issue, another stated that temporary files that could not be overwritten lead to the problem. Most posts however, do not have a satisfactory, or decisive conclusion.

like image 134
klyd Avatar answered Nov 16 '22 02:11

klyd