|
httphelper使用webBrowser登录支付宝自动掉线
使用如下入口代码 ,使用timer控制随机时间点触发,但是两三次后就 result.html为string.empty.
望高手赐教
HttpHelper http = new HttpHelper();
HttpItem item = null;
//把webBrowser1登陆的cookie传给HttpHelper
item = new HttpItem()
{
URL = webBrowser1.Url.AbsoluteUri,//URL
Method = "Get",//URL 可选项 默认为Get
Cookie = cookie,//调用webBrowser1登陆的cookie
ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
};
HttpResult result = http.GetHtml(item);
webBrowser1_DocumentCompleted 获取cookies
//取当前webBrowser登录后的Cookie值
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref uint pcchCookieData, int dwFlags, IntPtr lpReserved);
private static string GetCookies(string url)
{
uint pcchCookieData = 0x100;
StringBuilder pchCookieData = new StringBuilder((int)pcchCookieData);
if (!InternetGetCookieEx(url, null, pchCookieData, ref pcchCookieData, 0x2000, IntPtr.Zero))
{
if (pcchCookieData < 0)
{
return null;
}
pchCookieData = new StringBuilder((int)pcchCookieData);
if (!InternetGetCookieEx(url, null, pchCookieData, ref pcchCookieData, 0x2000, IntPtr.Zero))
{
return null;
}
}
return pchCookieData.ToString();
}
|
|