HttpHelper 请从网络中搜索;
public partial class LoginTMall : Form
{
public LoginTMall()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
string postDate = getPostString();
HttpItem itemLogin = new HttpItem()
{
URL = "https://login.taobao.com/member/login.jhtml",
Method = "POST",
ContentType = "application/x-www-form-urlencoded",
Referer = "https://www.taobao.com/",
Postdata = postDate,
Cookie = CommonDB.tmailModel.cookie,
};
HttpHelper helperLogin = new HttpHelper();
HttpResult resultLogin = helperLogin.GetHtml(itemLogin);
CommonDB.tmailModel.cookie = resultLogin.Cookie;
string html = resultLogin.Html;
if (html.ToLower().Contains("gotoURL:\"\"".ToLower()) && html.ToLower().Contains("gotoTop:true".ToLower())) {
MessageBox.Show("登录成功!");
}
else
{
string namePwdNotMatch = "您输入的密码和账户名不匹配,请重新输入。";
string reInputcheckcode = "验证码错误,请重新输入";
string checkCodeNeedInput = "为了您的账户安全,请输入验证码。";
if (html.Contains(namePwdNotMatch))
{
MessageBox.Show(namePwdNotMatch);
return;
}
if (html.Contains(checkCodeNeedInput) || html.Contains(reInputcheckcode))
{
string checkCodeUrl = "<img id=http://www.likecs.com/\"J_StandardCode_m\" src=http://www.likecs.com/\"https://s.tbcdn.cn/apps/login/static/img/blank.gif\"";
int index = html.IndexOf(checkCodeUrl);
html = html.Substring(index, html.Length - index);
string datasrc = "data-src=http://www.likecs.com/\"";
index = html.IndexOf(datasrc);
html = html.Substring(index, html.Length - index);
html = html.TrimStart(datasrc.ToCharArray());
index = html.IndexOf("http://www.likecs.com/\"");
html = html.Substring(0, index);
setCheckCode(html);
MessageBox.Show(checkCodeNeedInput);
return;
}
}
}
private void setCheckCode(string url)
{
try
{
picBox.Image = Image.FromStream(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream());
} catch (Exception ex) { Text = ex.Message; } }
private void LoginTMall_Load(object sender, EventArgs e) { }
private string getPostString()
{
PostParaPair model = new PostParaPair();
string checkCode = txtCheckCode.Text.Trim();
if (checkCode.Length != 0)
{
model.Add(new PostParaPair()
{ Key = "TPL_checkcode", Value = checkCode });
}
string pwd = txtPwd.Text.Trim();
if (pwd.Length != 0)
{
model.Add(new PostParaPair() { Key = "TPL_password", Value = pwd }); }
string name = txtUName.Text.Trim();
if (name.Length != 0)
{
model.Add(new PostParaPair() { Key = "TPL_username", Value = name });
}
model.Add(new PostParaPair() { Key = "allp", Value = "assets_css=2.0.0/login_pc.css&enup_css=2.0.0/enup_pc.css&assets_js=2.3.8/login_performance.js" });