Real Software Forums
http://forums.realsoftware.com/

Trying to trace URL re-directs
http://forums.realsoftware.com/viewtopic.php?f=2&t=45983
Page 1 of 1

Author:  dscl [ Mon Nov 19, 2012 1:41 pm ]
Post subject:  Trying to trace URL re-directs

What I'm trying to do, at a very basic level, is take a URL and verify that the URL does not redirect. If it does I need to get at the end url. So for example if you put

http://www.kmart.com/shc/s/v_10151_1010 ... lectronics?

in your browser you actually end up at

http://www.kmart.com/tvs-electronics/v-1231469079?rdc=y

(I have no affiliation with kmart btw)

What I need to do is have a text box to put the first URL, resolve it, and get the second URL. Looking through the examples included with RealStudio 2011R2 I have found the following projects and their behavior...

HTTP Example
If I enter the first URL in and press 'GO' the result returns back what appears to be binary?

SimpleWebBrowser
If I enter the first URL the resulting page properly loads, but the URL bar is not updated to reflect the new URL

HTMLViewer
If I enter the first URL the resulting page properly loads, but the URL bar is not updated to reflect the new URL

Win32 Web Browser
Finally, the not only does the correct content load, but the URL bar IS updated with the new and correct URL

The problem is that last example I can't make heads or tales of... Additionally I don't even need to see the rendered page contents... just the final location URL. Does anyone know how I could do this?

Thanks!

Author:  charonn0 [ Mon Nov 19, 2012 1:57 pm ]
Post subject:  Re: Trying to trace URL re-directs

HTTP redirects are detectable in the HTTPSocket's HeadersReceived event. A Redirect would likely use an HTTPStatus of 301 or 302. In a 301 or 302 redirect, the Headers passed to the HeadersReceived event contain a value called "Location" which is the URL to redirect to.

For example, here's the raw HTTP transaction with that KMart URL:

Request:
Quote:
GET /shc/s/v_10151_10104_Computers+%26+Electronics HTTP/1.1
Host: http://www.kmart.com
Connection: keep-alive


Response:
Quote:
HTTP/1.1 301 Moved Permanently
Location: /tvs-electronics/v-1231469079?rdc=y


Example project

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/