How to catch page redirect

A

Abc

I have some code for loading HTML od web page:

String Something = "";

System.Net.WebClient WC = new System.Net.WebClient();

Something = WC.DownloadString(txtSomeAdress.Text);

txtResult.Text = Something



So, what is problem. If some page is redirecting to another page, than I got
HTML of this new page and it is ok. But I need url of this new page. How to
get it with C# or VB?



Thanks
 
I

Ignacio Machin ( .NET/ C# MVP )

I have some code for loading HTML od web page:

String Something = "";

System.Net.WebClient WC = new System.Net.WebClient();

Something = WC.DownloadString(txtSomeAdress.Text);

txtResult.Text = Something

So, what is problem. If some page is redirecting to another page, than I got
HTML of this new page and it is ok. But I need url of this new page. How to
get it with C# or VB?

Thanks

You can check if the BaseAddress property of the WebClient is the same
you asked, if not a redirection occurred.
 
J

Jay R. Wren

I don't think this is possible.

The alternative is to use WebRequest instead of WebClient.

WebRequest webRequest =
WebRequest.Create("http://localhost:2121/");

var response = webRequest.GetResponse();

var reader = new
System.IO.StreamReader(response.GetResponseStream());
var Something = reader.ReadToEnd();
var endUrl = response.ResponseUri.ToString();

I hope this helps.
 
P

Paul

Use HTTPWebRequest/HTTPWEBRESPONSE

You also need to use the status field from the response to identify the
redirect, and then iterate the header and identify the target uri. I think
thats it any way been a while since I built a proxy.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top