1

I want to get HTML code of B page. Unfortunately site requires to open A page first to get session_id, after it I can finally open webpage I wanted. What is solution to get html code of B page? I try do it with WebClient, but session_id is probably not saved.

        var client = new WebClient();
        client.DownloadString("http://moria.umcs.lublin.pl/link/");
        client.DownloadString("http://moria.umcs.lublin.pl/link/grid/1/810");
Kel
  • 7,680
  • 3
  • 29
  • 39
teaperr
  • 91
  • 1
  • 6

2 Answers2

2

It depends on how the server tracks that you have already visited page A when you visit page B.

Most likely it uses some kind of session ID, which is probably saved in cookies. Examining HTTP request and response headers in any browser's developer tools can get you an idea of what this website does to track the user.

If you need to be able to store session ID in cookies, cookies-aware web-client sample is given here

Community
  • 1
  • 1
Kel
  • 7,680
  • 3
  • 29
  • 39
1

I would use HttpWebRequest instead of WebClient. I did not see any method in WebClient where you can get or set cookies. Take a look at this MSDN link. Your code for the initial request would be something like in the link. For the next request to another page, set the CookieContainers with the cookies from the response that you got from the initial request; before you request for the response.

https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer(v=vs.110).aspx