Home All Groups Group Topic Archive Search About

How to catch page redirect

Author
26 May 2009 12:22 PM
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

Author
27 May 2009 1:28 AM
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.
--
Jay R. Wren

Show quoteHide quote
"Abc" <i***@abc.com> wrote in message news:gvgmtq$pgo$1@sunce.iskon.hr...
> 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
>
>
Author
27 May 2009 9:24 AM
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


Show quoteHide quote
"Jay R. Wren" <jrw***@xmtp.net> wrote in message
news:92B56162-59CE-453A-AFC9-FDB6A4BA5FE2@microsoft.com...
>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.
> --
> Jay R. Wren
>
> "Abc" <i***@abc.com> wrote in message news:gvgmtq$pgo$1@sunce.iskon.hr...
>> 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
>>
>>
Author
27 May 2009 4:40 AM
Cor Ligthert[MVP]
Hi,

That is probably expressly done to prevent persons from stealing

Cor

Show quoteHide quote
"Abc" <i***@abc.com> wrote in message news:gvgmtq$pgo$1@sunce.iskon.hr...
>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
>
>