Welcome to WebmasterWorld Guest from 18.104.22.168
Forum Moderators: ocean10000
I have an interesting one here. I have some code that I've been using for years to pull down HTTP content as needed. However, I've just run into a situation that I've never seen before, and can't quite figure a way around ...
Background: If a URL fed to MSXML2.XMLHTTP via VBScript returns a 302 "redirect" when loaded - VBScript will crap out on the page load due to
security settings in IE, if the redirected URL is in another domain. You won't get any content back as a part of the response, and the HTTP status code actually comes back as "0". However ... if you enable the "Access data sources across domains" option in the security settings for IE - the MSXML2.XMLHTTP control will follow the 302 path and
eventually get the final result page and return the contents to you.
(/RANT-ON ... I shouldn't have to change settings in IE to control how my VBScript program will work! Ugh! /RANT-OFF)
However, I would like to detect this 302 activity and track it from the starting page to the ending page. For instance, here's WGET tracking a
two-layer redirect from a Feedburner link that demonstrates the situation:
Resolving www.geffen.com... 22.214.171.124
Connecting to www.geffen.com¦126.96.36.199¦:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8,294 (8.1K) [text/html]
Here's some code I put together, to try to loop through each redirect until a final non-302 result is returned ... and state what the final link was. But I can't seem to find any way to get this concept to work based on what MSXML2.XMLHTTP provides me, given its interaction with Internet Explorer. Basically, if I enable the "Access data sources across domains" the control will simply follow the 302's and not tell me about it, and return the final page but with a link that
(technically) doesn't match. If I disable the option, the GET performed by XMLHTTP craps out, returns a 0 result code.
Any thoughts on a way to accomplish this? Is it even possible, or am I trying to do something that is completely outside of the control provided by MS?
Thanks in advance ...
Const READYSTATE_UNINITIALIZED = 0, _
READYSTATE_INITIALIZED = 1, _
READYSTATE_LOADED = 2, _
READYSTATE_INTERACTIVE = 3, _
READYSTATE_COMPLETE = 4
MaxLoadTime = 20
MaxLoops = 10
url = "http://feeds.geffen.com/artist/robzombie/content?m=145"
StatusResult = 302
LoopCount = 0
wscript.echo "START: " & url
Do while loopcount < maxloops and statusresult = 302
loopcount = loopcount + 1
CheckPageLoadTime = 0
PageLoadStartTime = now()
Set objHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
Call objHTTP.Open("GET", url, TRUE)
Do Until objHTTP.ReadyState = READYSTATE_COMPLETE or CheckPageLoadTime > MaxLoadTime
PageLoadEndTime = now()
CheckPageLoadTime = DateDiff("s", PageLoadStartTime, PageLoadEndTime)
HTTPGET = objHTTP.ResponseText
StatusResult = objHTTP.Status
HTTPRedirectLocation = objHTTP.GetResponseHeader("Location")
If CheckPageLoadTime > MaxLoadTime then
IF StatusResult = 302 then
wscript.echo "REDIRECT: " & HTTPRedirectLocation
url = HTTPRedirectionLocation
wscript.echo "END: " & url
wscript.echo "HTTP Status: " & StatusResult
wscript.echo "Redirects: " & loopcount
Here's my results with the security option set to disabled:
HTTP Status: 0
And here's my result with the security option set to enabled:
HTTP Status: 200
So, to me, it seems as though it is impossible to trace the string of 302's through the MSXML2.XMLHTTP control?
I've tried working a bit with the SetOption method of MSXML2.ServerXMLHTTP.4.0, since I saw some people were able to have that control ignore SSL errors. Sadly, no luck...
Thanks in advance....