Is it possible to Post some data from window based app to a web-server ? Lets be practical
ASCIIEncoding encodedText = new ASCIIEncoding();
string postData = string.Format("txtUserID={0}&txtPassword={1}", txtUName.Text, txtPassword.Text);
byte[] data = encodedText.GetBytes(postData);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://www.aimlifes.com/office/Login.aspx");
webRequest.Method = "POST";
webRequest.ContentType = "text/html";
webRequest.ContentLength = data.Length;
Stream strm = webRequest.GetRequestStream();
strm.Write(data, 0, data.Length);
txtUrlData.Text = GetPageHtml("http://www.aimlifes.com/office/ReceiveRecharge.aspx");
strm.Close();
GetPageHtml Function:
public string GetPageHtml(String Url)
{
WebClient wbc = new WebClient();
return new System.Text.UTF8Encoding().GetString(wbc.DownloadData(Url));
}
What i’m trying is Login To xyz.com site using given credential and fetch the html data in a TextArea. GetPageHtml() function fetch’s the html data. But the main problem is Posting the login details is not working, i mean m not able to get login to the xyz.com
If the site uses cookies to tack authenticated users you might try this: