How do I know way2sms Login is successfull or not using HttpWebRequest and HttpWebResponse?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello Everyone,
I want to check enter userid and password is correct or not. I create one application for sending sms using Way2sms account. I am not getting how to check entered userid and password is correct or not.

My code :
<pre class="prettyprint namespace Way2sms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
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 + "&password=" + password);

string responsehtml = Encoding.UTF8.GetString(data);

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&catnamedis=Birthday&Action=sa65sdf656fdfd&chkall=on&MobNo=" + no + "&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]
<br/>
Can someone tell me how I check login successfull or not ? I am new in this field i.e. HttpWebRequest, HttpWebResponse.






View the full article
 

Similar threads

M
Replies
0
Views
537
Mattia Fanti
M
C
Replies
0
Views
188
castlehere
C
Z
Replies
0
Views
167
Zarticho
Z
Back
Top