简体   繁体   中英

how to login into a website and get redirected url contents using c#

I am trying to learn a process where I can login into a website and get download all the html of the website I can do this using webClient.DownloadString(@url); but the problem is that after login How can I get the redirected url. as I get the redirected url I can use this method please help me.

You should do a fiddler trace to see if the redirection is an HTTP redirect, or is it javascript-inititated on the returned page.

Assuming it is an HTTP redirect (a 301 or a 302), you can use HttpWebRequest / HttpWebResponse to fetch the redirected location. On HttpWebRequest , set AllowAutoRedirect=false . After the request is made, check the HttpWebResponse object for the StatusCode property. If HTTP status code is 301 or 302, check the Location header in the Headers property of the HttpWebResponse .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM