Say I have a web page that prompts for input then searches a database for the user's username and password, then decrypts the password and checks if the entered password is the same as the user's password in the database. What if I want to switch the login to a C# winforms app? How could I make that http request with the username and entered password, then having the site accept the username/password strings and search the db for those the same way I said earlier, then send a bool of true: the user entered correct info or false: the user entered incorrect info. How could I do that?
Asked
Active
Viewed 6,868 times
1
-
Why the `php` tag here? what API should you have to call? – sujith karivelil Jan 02 '17 at 05:39
-
so you want to call the site from the windows form? – CodingYoshi Jan 02 '17 at 05:49
-
1try to look here http://stackoverflow.com/questions/4088625/net-simplest-way-to-send-post-with-data-and-read-response – Beginner Jan 02 '17 at 05:57
1 Answers
2
To do so you first need to know how the server accept the request which is most likely by the post method since you have to input the user name and password and then you will have to get the input the string which can be obtained using a some browser extensions like Live Http Headers. it should look something like this
http://yourwebsite/extension
POST /extension HTTP/1.1
Host: yourwebsite
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Length: 85
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive
HereShouldBeThePoststring
Then you would create a httpwebrequest using the website url
using System.Net;
string postUrl = "YourWebsiteUrlWithYourExtension";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postUrl);
then you would post your data
string postString = "ThePostStringYouObtainedUsingLiveHttpHeaders";
request.Method = "POST";
byte[] Content = Encoding.ASCII.GetBytes(postString);
request.ContentLength = Content.Length;
using (Stream stream = request.GetRequestStream())
{
stream.W
then you would get the response string
string responsestring = null;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
responsestring = reader.ReadToEnd();
}
then you would parse your string to get the data your need. A good library for parsing is Html Agility Pack.

Diab
- 124
- 1
- 10