0

I have URLs of some websites. I have to open those URLs and verify some links on those pages. The problem is that some URLs get redirected to other URLs .

Is there some way through which I can pass my original URL string and get the FINAL redirected URL back?

Example: I am trying with this URL:

http://www.example.com/script/java.php?option=rotateur&rotateur=232323

i am getting this:

example.net/script/pop_packcpm.php?k=54fb17d51c8f61411434.2188237&h=1ae8c47926980359b819222538d776d49b40fb25&id=0&ban=1411434&r=321957&ref=&data=&subid=&new=1&exp=prpd&dx=%3D%3DAD&pkr=%3D%3DwAKZwBKZgD&psr=%3DEwAPcABFghR&scr=%3DQQBPUQBHghB&ver=.0

I want this FINAL url:

example.net/casual-shoes?ccode=achu75df8d5d54f5cbed491c4f3263&utm_source=ach&utm_medium=CPC&utm_content=offer&utm_campaign=cshoes#

I tried to use following code:

HttpWebResponse webResponse; 
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.AllowAutoRedirect = false; 
webRequest.Timeout = 10000;
webRequest.Method = "HEAD"; 
using (webResponse = (HttpWebResponse)webRequest.GetResponse()) 
{ 
    string header = webResponse.Headers.ToString();
    if((int)webResponse.StatusCode>=300 &&(int)webResponse.StatusCode<= 399) {
        uriString = webResponse.Headers["Location"]; 
        Console.WriteLine("Redirect to " + uriString ?? "NULL");
        webResponse.Close();
    } 
}

satyawan
  • 1
  • 3

0 Answers0