ログインが成功したかどうかを確認する方法がわかりません。httpwebrequestとhttpresponseを使用してログインの成功を確認するにはどうすればよいですか?
私のコード
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 + "&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&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;
}
これがway2smsを使用してSMSを送信するための私のコードです。ユーザー名とパスワードの入力が正しいかどうかを確認したいですか?どうすれば確認できますか?