httphelper类在引用时,用代理的情况,如果代理不可用,经常出错。
[C#] 纯文本查看 复制代码 private void GetCode()//获取验证码
{
if (cbProxy.Checked == true)
{
if (proxyipnum < proxylist.Count)
{
proxyip = proxylist[proxyipnum];
proxyipnum++;
lblProxy.Text = "当前使用的代理是:" + proxyip;
}
}
item = new HttpItem()
{
URL = "http://www.sqee.cn/member.php?mod=register",
Method = "GET",
ProxyIp = proxyip,
};
result = http.GetHtml(item);
Cookies = result.Cookie;
retCode = result.Html;
param = Params(retCode);
try
{
item = new HttpItem() //[size=5]代理不可用时,提示:未将对象引用 到实例!!错误一。本地正常。代理可用时正常。[/size]
{
URL = "http://www.sqee.cn/misc.php?mod=secqaa&action=update&idhash=q" + param[6].Substring(1) + "&0.2664431149100278",
Method = "GET",
Referer = "http://www.sqee.cn/member.php?mod=register",
Cookie = Cookies,
ProxyIp = proxyip,
};
result = http.GetHtml(item);
Cookies += result.Cookie;
retCode = result.Html;
gifAnser = GetAnser(Utilities.GetMidStr(retCode, "patronage/images/y-", "."));
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
item = new HttpItem()
{
URL = "http://www.sqee.cn/misc.php?mod=seccode&action=update&idhash=" + param[6] + "&0.4454971277934601&modid=member::register",
Method = "GET",
Referer = "http://www.sqee.cn/member.php?mod=register",
Cookie = Cookies,
ProxyIp = proxyip
};
result = http.GetHtml(item);
Cookies += result.Cookie;
retCode = result.Html;
update = Utilities.GetMidStr(retCode, "&update=", "&");
item = new HttpItem()
{
URL = "http://www.sqee.cn/misc.php?mod=seccode&update=" + update + "&idhash=" + param[6],
Method = "GET",
Referer = "http://www.sqee.cn/member.php?mod=register",
Cookie = Cookies,
ProxyIp = proxyip,
ResultType = ResultType.Byte
};
result = http.GetHtml(item);
Cookies += result.Cookie;
if (result.ResultByte.Length < 8000) return;
pictureBox1.Image = Utilities.GetImageFromByte(result.ResultByte);//获取验证码[size=6] 错误二,本地正常,代理正常时正常,代理不可用时,显示对像NULL[/size]
//textBox1.Text = result.ResultByte.Length.ToString();
//if (result.ResultByte.Length > 8000)
//{
// pictureBox1.Image = Utilities.GetImageFromByte(result.ResultByte);//获取验证码
//}
//else MessageBox.Show("获取验证码错误,代理有可能不能使用!","提醒");
}
|