homepage Welcome to WebmasterWorld Guest from 54.161.192.61
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Tracing a stream of 302's
toomer

5+ Year Member



 
Msg#: 3444 posted 10:34 pm on Jun 6, 2006 (gmt 0)

Hi all ...

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:

1. WGET [feeds.geffen.com...]
HTTP request sent, awaiting response... 302 Moved Temporarily
Location:
[feeds.feedburner.com...]
[following]

2. WGET [feeds.feedburner.com...]
HTTP request sent, awaiting response... 302 Moved Temporarily
Location:
[geffen.com...]
ource=rss&utm_campaign=rss&utm_medium=News&utm_content=nid_8031
[following]

3. WGET
[geffen.com...]
tm_source=rss&utm_campaign=rss&utm_medium=News&utm_content=nid_8031
Resolving www.geffen.com... 192.251.67.164
Connecting to www.geffen.com¦192.251.67.164¦: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)
objHTTP.Send

Do Until objHTTP.ReadyState = READYSTATE_COMPLETE or CheckPageLoadTime > MaxLoadTime

wscript.sleep 100

PageLoadEndTime = now()

CheckPageLoadTime = DateDiff("s", PageLoadStartTime, PageLoadEndTime)

Loop

HTTPGET = objHTTP.ResponseText
StatusResult = objHTTP.Status
HTTPRedirectLocation = objHTTP.GetResponseHeader("Location")

If CheckPageLoadTime > MaxLoadTime then
wscript.echo "TIMEOUT"
end if

IF StatusResult = 302 then

wscript.echo "REDIRECT: " & HTTPRedirectLocation
url = HTTPRedirectionLocation

end if

loop

wscript.echo "END: " & url
wscript.echo
wscript.echo "HTTP Status: " & StatusResult
wscript.echo "Redirects: " & loopcount

Here's my results with the security option set to disabled:

START: [feeds.geffen.com...]
END: [feeds.geffen.com...]

HTTP Status: 0
Redirects: 10

And here's my result with the security option set to enabled:

START: [feeds.geffen.com...]
END: [feeds.geffen.com...]

HTTP Status: 200
Redirects: 1

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....

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved