How to get MSXML IXMLHTTPRequest to handle HTTP redirects?
Asked Answered
T

2

7

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!

Tredecillion answered 18/6, 2013 at 22:21 Comment(1)
Is there any sample code and sample url that demonstrate the problem? The E_ACCESSDENIED returned from the Send call seems strange.Refectory
S
2

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.

Slapbang answered 26/3, 2014 at 17:34 Comment(2)
The test url is the following mathstat.uottawa.ca/~rsmith/Zombies.pdf which redirects to mysite.science.uottawa.ca/rsmith43/Zombies.pdf Do you have a citation for the strict redirect policy? I searched high and low and could find no useful info on this topic. I also mentioned in my original question that I tried IXMLHttpServerRequest, IXMLHttpServerRequest2 and MSXML v6, with no change in behavior. In the end I gave up and switched to WinHTTP. Works great now.Tredecillion
I can't find a single place in the documentation where the origin policy is actually stated. That said, mathstat.uottawa.ca is a different origin than mysite.science.uottawa.caSlapbang
T
0

I think that it could be because your IXMLHTTPRequest2::Open call does not pass in an instance of your IXMLHTTPRequest2Callback class.

Taub answered 21/3, 2014 at 1:0 Comment(1)
I mentioned briefly that I tried the IXMLHttpRequest async request callback (version 1). IXMLHTTPReqeuest2 handles redirect fine (sync or async), and we use it on WinRT, but the code in question needs to run on XP for example, and so I was using the older IXMLHTTPRequest.Tredecillion

© 2022 - 2024 — McMap. All rights reserved.