0
我已经在asp.net中使用c#与远程服务器连接了一个桌面应用程序。我能够连接,但是如何显示我的登录成功与否。之后,我想从远程服务器检索数据..........所以PLZ帮助我。我写了下面的代码..............有没有更好的方式如何从远程服务器获得响应
try
{
string strId = UserId_TextBox.Text;
string strpasswrd = Password_TextBox.Text;
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "UM_email=" + strId;
postData += ("&UM_password=" + strpasswrd);
byte[] data = encoding.GetBytes(postData);
MessageBox.Show(postData);
// Prepare web request...
//HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/ruhit/basic_framework/index.php?menu=login=" + postData);
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create("http://www.facebook.com/login.php=" + postData);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
MessageBox.Show("u r now connected");
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
// WebResponse response = myRequest.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string str = reader.ReadLine();
while (str != null)
{
str = reader.ReadLine();
MessageBox.Show(str);
}
reader.Close();
newStream.Close();
}
catch
{
MessageBox.Show("error connecting");
}