|
CookieCollection pubcook = new CookieCollection();
private Image byteArrayToImage(byte[] Bytes)
{
MemoryStream ms = new MemoryStream(Bytes);
Image outputImg = Image.FromStream(ms);
return outputImg;
}
public Image GetKey(string imgurl, out CookieCollection KeyCook)//参数为cookie集合
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = imgurl,//URL 必需项
Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
//Encoding = Encoding.Default,
ResultType = ResultType.Byte,
ResultCookieType = ResultCookieType.CookieCollection
};
//得到HTML代码
HttpResult result = http.GetHtml(item);
KeyCook = result.CookieCollection;//cookie集合
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
//表示访问成功,具体的大家就参考HttpStatusCode类
}
//表示StatusCode的文字说明与描述
string statusCodeDescription = result.StatusDescription;
//把得到的Byte转成图片
Image img = byteArrayToImage(result.ResultByte);
return img;
}
public string Loninmt(string key, CookieCollection Cook)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "https://passport.meituan.com/account/signin?service=www&continue=http%3A%2F%2Fwww.meituan.com%2Faccount%2Fsetssid%3Fcontinue%3Dhttp%3A%2F%2Fsjz.meituan.com%2F&mtt=1.index%2Ffloor.0.0.hzfbdqog",
Method = "POST",
ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
Postdata = "csrf=yy8UTYY0_MNvhp1TM3HY0o_J8g5y7LqBPLunAdI78WAulIbstO9vr1W-tc_eVtXl&email=12345678&password=123456&captcha="+key+"&remember_username=1&fingerprint=0-6-1-32uc%7C5b%7C5k%7C55%7C5j%7C4o%7Cjc%7C68%7C2t3%7Cfd%7C6o%7C87&origin=account-login",
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36",
Host = "passport.meituan.com",
Referer = "https://passport.meituan.com/account/signin?service=www&continue=http%3A%2F%2Fwww.meituan.com%2Faccount%2Fsetssid%3Fcontinue%3Dhttp%253A%252F%252Fsjz.meituan.com%252F&mtt=1.index%2Ffloor.0.0.hzfbdqog",
CookieCollection = Cook,
ResultCookieType = ResultCookieType.CookieCollection,
};
item.Header.Add("X-Requested-With", "XMLHttpRequest");
HttpResult result = http.GetHtml(item);
result = http.GetHtml(item);
return result;
}
private void Form1_Load(object sender, EventArgs e)
{
string imgurl = "http://login.55.com/safecodelogin.jpg";
pictureBox1.Image = GetKey(imgurl,out pubcook);//获取验证码
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = Loninmt(textBox2.Text, pubcook);
}
不出验证码的情况下,登录成功,但出了验证码,用验证码图片得到的cookie去post,得到的结果是验证码错误,老大帮忙看下吧
|
|