+ Reply to Thread
Results 1 to 2 of 2

Thread: Detect URL if being redirected

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    15

    Detect URL if being redirected

    I am TRYING to get the response of a URL but sometimes it is being redirected to another URL
    so for example if i GET : http://site1.com
    It redirects to : http//site2.com
    And i get a HttpStatusCode.OK instead of Redirect Code.
    So finally i`d like to detect when the url is redirected.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    22
    You need to use the AllowAutoRedirect property , here is an example from MSDN :
    Code:
    			// Create a new HttpWebRequest Object to the mentioned URL.
    			HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com");	
    			myHttpWebRequest.MaximumAutomaticRedirections=1;
    			myHttpWebRequest.AllowAutoRedirect=true;
    			HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts