how to get response from remote server

Posted by ruhit on Stack Overflow See other posts from Stack Overflow or by ruhit
Published on 2010-12-17T05:32:07Z Indexed on 2010/12/28 10:53 UTC
Read the original article Hit count: 199

Filed under:

I have made a desktop application in asp.net using c# that connecting with remote server.I am able to connect but how do i show that my login is successful or not. After that i want to retrieve data from the remote server..........so plz help me.I have written the below code..............is there any better way

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");
        }

© Stack Overflow or respective owner

Related posts about ASP.NET