Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get MSXML IXMLHTTPRequest to handle HTTP redirects?

Situation: 1) I need to make HTTP[S] networking calls in C++ on Windows for our DLL. 2) Need to support at least XP (I guess SP3 is ok) 3) no ATL, no MFC, no IE

Question: I recently switched from Boost cpp-netlib to using MSXML's IXMLHTTPRequest for our (very simple) networking needs on windows. While everything seemed to work great, we noticed that redirects don't work. In fiddler I get a HTTP 302, followed by the second successful HTTP 200 request/response.

However in the actual C++ code I get E_ACCESSDENIED from IXMLHTTPRequest->Send and the HTTP response code is zero. So in the code I have no way to know what actually happened.

Since from Fiddler everything was working, I tried making it async and checking the callback, also tried IXMLHttpServerRequest, IXMLHttpServerRequest2 and MSXML v6, but none worked.

Note: We use IXMLHttpRequest2 on WinRT and that works fine (handling the OnRedirect event).

Is there anyway to get MSXML's IXMLHTTPRequest to handle redirects?

Or do I need to switch to WinInet/WinSockets/WinHttp? I take it I need to use WinHttp (since I need to support Windows Services/IIS, which WInInet apparently doesn't, and WinSockets is too low level for my needs I think).

Thanks!

like image 756
ryanb Avatar asked Jun 18 '13 22:06

ryanb


1 Answers

I haven't had to do this in a long time so this answer might be a little dated. As I recall, the redirect policy for IXMLHTTPRequest is very strict. Is the redirect using the same origin as the original request? If so, that may violate the security restrictions which is causing your error.

If that is in fact the problem, try IServerXMLHTTPRequest instead.

like image 119
David Banister Avatar answered Oct 04 '22 23:10

David Banister