|
HttpHelper百度联盟登入有没有成功的?我老是登入不上- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = "http://cas.baidu.com/?action=image",//URL 必需项
- Referer = "http://union.baidu.com/customerLogin.html?fromu=http%3A%2F%2Funion.baidu.com%2F",//来源URL 可选项
- UserAgent = "User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1",//用户的浏览器类型,版本,操作系统 可选项有默认值
- ResultType = ResultType.Byte
- };
- HttpResult result = http.GetHtml(item);
- code_cookie = result.Cookie;
- pictureBox1.Image = byteArrayToImage(result.ResultByte);
- }
- string code_cookie;
- private Image byteArrayToImage(byte[] Bytes)
- {
- MemoryStream ms = new MemoryStream(Bytes);
- Image outputImg = Image.FromStream(ms);
- return outputImg;
- }
- private void button7_Click(object sender, EventArgs e)
- {
- HttpHelper http = new HttpHelper();
- string fr_gdcode = textBox1.Text.Trim();
- HttpItem item = new HttpItem()
- {
- URL = "http://cas.baidu.com/?action=login",//URL 必需项
- Method = "post",//URL 可选项 默认为Get
- Referer = "http://union.baidu.com/customerLogin.html?fromu=http%3A%2F%2Funion.baidu.com%2F",//来源URL 可选项
- UserAgent = "User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1",//用户的浏览器类型,版本,操作系统 可选项有默认值
- Postdata = "entered_login="+textBox3.Text+"&entered_password="+textBox4.Text+"&sid=&pwd=&entered_imagecode=" + fr_gdcode + "&appid=6&fromu=http%253A%252F%252Funion.baidu.com%252Fuserlogin.action&selfu=&senderr=1&login2=%E7%99%BB%E5%BD%95",//Post数据 可选项GET时不需要写
- Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*",// 可选项有默认值
- ContentType = "application/x-www-form-urlencoded",
- Allowautoredirect = false,//是否根据301跳转 可选项
- Cookie = code_cookie.Replace("path=/,", "").Replace("path=/", "")
- };
- HttpResult result = http.GetHtml(item);
- string cookie = item.Cookie;
- //这里要再次New一个,否则最少也应该修改一下Method,要不然还是继承上面的Post方式
- item = new HttpItem()
- {
- URL = "http://union.baidu.com/client/#/account/overview",//URL 必需项
- Method = "get",//URL 可选项 默认为Get
- Referer = "http://union.baidu.com/client/#/",//来源URL 可选项
- Cookie = cookie
- };
- result = http.GetHtml(item);
- string html = result.Html;
- textBox2.Text = cookie;
- }
- }
复制代码 |
|