How to enter HTML form using POST files in C # (.NET)?

For example, there is this site: www.azet.sk

There is a username and password on the right, I want my application to go into this web application and extract data from my account into a C # (.NET) application and work with it. The goal is to keep the "login" alive and send vars using the POST method. Is there a tutorial or a simple script with examples to find out?

+2
source share
3 answers
string username = "your"; string password = "password"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://moje.azet.sk/prihlasenie.phtml?KDE=www.azet.sk%2Findex.phtml%3F"); using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII)) { writer.Write("nick=" + username + "&password=" + password); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //Retrieve your cookie that id your session //response.Cookies using (StreamReader reader = new StreamReader(response.GetResponseStream()) { Console.WriteLine(reader.ReadToEnd()); } 
+5
source

Part of the entrance should be relatively easy.

Use System.Net.WebClient and the UploadValues() method to submit form data. Look at the HTML source for the field values โ€‹โ€‹for POST.

Most forms-based authorization mechanisms use an HTTP cookie to allow a user to log in. So, after you complete the POST, look at the WebClient ResponseHeaders collection for the "Set-Cookie:" header.

Save the cookie value for subsequent GET / POST on the website.

You will probably find that โ€œretrieving data from your account and working with itโ€ is much more difficult (for example, screen scripting, etc.).

Here's a link with a few examples:

http://codebetter.com/blogs/brendan.tompkins/archive/2005/05/18/63329.aspx

+4
source

Take a look at the WebBrowser control. You can navigate anywhere and access the document and its controls programmatically.

0
source

Source: https://habr.com/ru/post/1303411/


All Articles