PDA

View Full Version : XMLHTTP, SSL, and IE


babadi
02-01-2006, 09:24 PM
Hi folks,

I'm trying to do use XMLHTTP to do a POST in the following JavaScript snippet.

var xml = new ActiveXObject('Microsoft.XMLHTTP');
xml.open("POST", "http://some/url/", false);
xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xml.send("username=myusername&password=mypassword");
document.write(xml.responseText);

This works fine in Internet Explorer 6 SP2. However, I would like to use https, rather than http. When I change the URL to https and reload the page, I get an error: "The download of the specified resource has failed". As a test, I tried running the same code in Firefox (changing the first line to "var xml = new XMLHttpRequest()"), and this worked for both http and https perfectly, although using https causes a dialog box to pop up asking the user to accept the SSL certificate. Unfortunately, I really need this to work in IE.

I found a couple of discussions on Usenet about this, but none that seemed to give me a clear answer to this issue. Does anybody know what might be wrong or how I might fix it?

Thanks,
Martin

liorean
02-01-2006, 09:40 PM
It's the same origin policy again. JavaScript doesn't allow file access to other domains than the originating one. The http and https protocols have different default ports and thus will not count as the same domain even if the domain part of the URI is otherwise identical.

babadi
02-01-2006, 09:59 PM
Thanks for your reply, however I don't think this is the issue, as my script resides on a page on a separate server from the one I'm POSTing to. If this were the problem, I figure neither http or https would work. (I believe this is allowed through some obscure IE setting.)

thanks,
Martin

nilanka_shani
10-27-2006, 08:53 AM
Hi Babadi,

Im getting the same problem. The only difference is that im using a XMLHTTPRequestClass object.

I want to post an XMLHTTPRequest to a server for the screen scrapping
purpose. but it always throws an exception .

{"The download of the specified resource has failed.\r\n" }
[System.Runtime.InteropServices.COMException]:
{System.Runtime.InteropServices.COMException}
System.Object: {System.Runtime.InteropServices.COMException}
_className: null
_COMPlusExceptionCode: -532459699
_exceptionMethod: <undefined value>
_exceptionMethodString: null
_helpURL: null
_HResult: -2146697208

This is the code I have written.


MSXML.XMLHTTPRequestClass lobjRequest = new XMLHTTPRequestClass();

string lstrNull = null;
object lobjNull =lstrNull;
string lstrBody="";

lobjRequest.open("POST","https://xxxxxxxxxxx, false, lobjNull,
lobjNull);

lobjRequest.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
lobjRequest.setRequestHeader("Referer","http://xxxxxxxx");

string lstrRequest="xxxxxxxxxxxxxxxxx";

lobjRequest.send(lstrRequest);
lstrBody = lobjRequest.responseText;


The same code works fine when the request is posted to an http url.

Is there any solution for this? I tried to use WinHttp. But it also
asks for a client certificate. If you have found any solution for this please reply me. it will be a great relief for me.