Access page protected by login with C #

2

I need to make a script to capture links from a page, it happens that this page is protected by login, I have this login but I do not know how to make a request to be able to access this protected page. It would look something like this:

  • Access page ( https://nome-da-página )
  • Log in using email and password (In this part I'm having difficulties, I have this email and password, but I'm not using it)
  • Capture link
asked by anonymous 19.09.2014 / 18:37

1 answer

1

If you are going to make the request via C #, then one of the minimalist ways of doing this is with the class System.Net.WebClient .

You can authenticate by using the Credentials and UseDefaultCredentials properties.

Example:

WebClient foo = new WebClient();
foo.UseDefaultCredentials = true;
foo.Credentials = new NetworkCredential("John Doe", "123456");

Then you download the content like this:

string endereco = "https://nome-da-página/LinksQueVouRoubar";
string resposta = client.DownloadString(endereco);

The string resposta will contain all the HTML of the result. Now, just pan.

    
19.09.2014 / 19:24