Access login protected page with C#

Asked

Viewed 924 times

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 access this protected page. It would be something like that:

  • View page (https://nome-da-página)
  • Login using email and password (In this part I’m having difficulties, I have this email and password, but I’m not using it)
  • Link capture

1 answer

1

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

You can authenticate using the properties Credentials and UseDefaultCredentials.

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 = foo.DownloadString(endereco);

A string resposta will contain all the HTML of the result. Now just scan.

  • in "string reply = client.Downloadstring(address);" where is the statement of . client ?

  • 1

    @Eltona.Pering is the same that was instantiated before, I edited to make it clear.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.