I want to create a desktop application (c#.net) to submit a login.php form and read the response if the login sucess or not
<?php
?>
<html>
<body>
<form action="checklogin.php" method="POST">
<input type="text" name="name" size="20"><br/>
<input type="password" name="password" size="20"><br/>
<input type="submit" name="submit">
</form>
</body>
</html>
In c# i have created a form having two text fields for name and password
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace loginphp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private String readHtmlPage(string url)
{
String username = "rk";
String password = "rk";
String result = "";
String strPost = "name=" + username + "&password=" + password ;
StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception e)
{
return e.Message;
}
finally
{
myWriter.Close();
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
sr.Close();
}
return result;
}
private void button1_Click(object sender, EventArgs e)
{
label3.Text= readHtmlPage("http://localhost/spotkeys/login.html");
}
}
}
but it only returns the following
<html>
<body>
<form action="checklogin.php" method="POST">
<input type="text" name="name" size="20">
<input type="password" name="password" size="20">
<input type="submit" name="submit">
</form>
</body>
</html>
how can i sumbit a php form using c# and read the response if login sucess or not