|
已解决参考帖子:http://www.sufeinet.com/thread-5199-1-1.html
带验证码登陆不成功,一直返回“本次请求并未返回任何数据”
我的代码如下
下面是获取验证码的代码
[code=csharp]
string code_cookie;
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.888funcity.com/fcity/login.php?language=simplified&referral=",//URL 必需项
//URL = "http://g818city.com/appg/draw_gd.php",
Method = "get",//URL 可选项 默认为Get
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = "",//字符串Cookie 可选项
Referer = "",//来源URL 可选项
Postdata = "",//Post数据 可选项GET时不需要写
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
ContentType = "text/html",//返回类型 可选项有默认值
Allowautoredirect = false,//是否根据301跳转 可选项
};
HttpResult result = http.GetHtml(item);
item.Cookie = result.Cookie;
code_cookie = result.Cookie;
item.URL = "http://www.888funcity.com/fcity/draw_gd.php";
item.Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
item.Encoding = null;
item.ResultType = ResultType.Byte;
result = http.GetHtml(item);
pictureBox1.Image = byteArrayToImage(result.ResultByte);[/code]
下面是登陆的代码:- private void button7_Click(object sender, EventArgs e)
- {
- HttpHelper http = new HttpHelper();
- string fr_gdcode = textBox1.Text.Trim();
- HttpItem item = new HttpItem()
- {
- URL = "http://www.888funcity.com/fcity/login.php",//URL 必需项
- Method = "post",//URL 可选项 默认为Get
- Referer = "http://www.888funcity.com/fcity/login.php",//来源URL 可选项
- Postdata = "fr_username=feifei2014&fr_password=ff123456&fr_gdcode="+fr_gdcode+"&language=simplified&fr_language=simplified&fr_companycode=a2700&fr_querycheck=http%3A%2F%2Fwww.888funcity.com%2Ffcity%2Flogin.php%3Flanguage%3Dsimplified%26referral%3D",//Post数据 可选项GET时不需要写
- UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
- ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
- };
-
- code_cookie = code_cookie.Replace("path=/,", "").Replace("path=/", "");
- item.Cookie = code_cookie;
- HttpResult result = http.GetHtml(item);
- item.URL = "http://www.888funcity.com/fcity/system.php";
- item.Cookie = result.Cookie;
- result = http.GetHtml(item);
- string html = result.Html;
- StreamWriter sw = new StreamWriter("data.txt", true, Encoding.GetEncoding("gb2312"));
- sw.WriteLine(html);
- sw.Close();
- MessageBox.Show("完成!");
- }
复制代码 |
|