title: How to identify login successful using Httpwebrequest and httpwebresponse?
body: <p>I doesn't understand how do I check login is successful or not. How can I check login success using httpwebrequest and httpresponse?</p>
  
  <p>my <strong>Code</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Net;
  using System.IO;
  using System.Diagnostics;
  
  namespace Way2sms
  {
  public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
      private CookieCollection cc = new CookieCollection();
      private void Send_Click(object sender, EventArgs e)
      {
          string uid = txtUsername.Text.Trim();
          string password = txtpass.Text.Trim();
          string message = txtmsg.Text.Trim();
          string no = txtno.Text.Trim();
  
          try
          {
              WebBrowser wb = new WebBrowser();
  
              HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://site5.way2sms.com/Login1.action");
  
              req.Method = "POST";
              CookieContainer con = new CookieContainer();
              req.CookieContainer = con;
              req.CookieContainer.Add(GetC());
              req.KeepAlive = true;
  
              req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11";
  
              req.ContentType = "application/x-www-form-urlencoded";
              req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  
              req.Referer = "http://site5.way2sms.com/content/index.html";
  
              byte[] data = System.Text.Encoding.Default.GetBytes("username=" + uid + "&amp;password=" + password);
  
              req.ContentLength = data.Length;
  
              req.AllowAutoRedirect = true;
  
              req.ServicePoint.Expect100Continue = true;
  
              Stream str = req.GetRequestStream();
  
              str.Write(data, 0, data.Length);
  
              str.Close();
  
              HttpWebResponse res = (HttpWebResponse)req.GetResponse();
              wb.ScriptErrorsSuppressed = true;
              wb.DocumentText = new StreamReader(res.GetResponseStream()).ReadToEnd();
  
              webBrowser1.Navigate(wb.DocumentText);
  
  
              HttpWebRequest X = (HttpWebRequest)WebRequest.Create("http://site5.way2sms.com/quicksms.action");
              X.Method = "POST";
              X.CookieContainer = con;
              X.KeepAlive = true;
              X.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11";
  
              X.ContentType = "application/x-www-form-urlencoded";
  
              X.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  
              X.Referer = "http://site5.way2sms.com/jsp/InstantSMS.jsp";
  
              byte[] datax = Encoding.Default.GetBytes("HiddenAction=instantsms&amp;catnamedis=Birthday&amp;Action=sa65sdf656fdfd&amp;chkall=on&amp;MobNo=" + no + "&amp;textArea=" + message);
  
              X.ContentLength = datax.Length;
  
              X.AllowAutoRedirect = true;
  
              X.ServicePoint.Expect100Continue = true;
  
              str = X.GetRequestStream();
  
              str.Write(datax, 0, datax.Length);
  
              str.Close();
  
              HttpWebResponse resx = (HttpWebResponse)X.GetResponse();
  
              wb.DocumentText = new StreamReader(resx.GetResponseStream()).ReadToEnd();
          }
          catch (Exception ex)
          { 
  
          }
  
      }
      private CookieCollection GetC()
      {
  
          HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://site5.way2sms.com/");
  
          req.CookieContainer = new CookieContainer();
  
          req.CookieContainer.Add(cc);
  
          req.CookieContainer.Add(cc);
  
          req.KeepAlive = true;
  
          req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11";
  
          req.ContentType = "application/x-www-form-urlencoded";
  
          req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  
          req.Referer = "http://site5.way2sms.com/content/index.html";
  
          req.AllowAutoRedirect = true;
  
          req.ServicePoint.Expect100Continue = true;
  
          return ((HttpWebResponse)req.GetResponse()).Cookies;
      }
  </code></pre>
  
  <p>Here is my code for sending sms using way2sms. I want to check enter user name and password is correct or not? so How can I check?</p>