|
发表于 2013-8-24 15:58:15
|
显示全部楼层
苏飞老大,你写上去的这个在webBrowser中取Cookie的方法只适用于.net 2.0。建议改成通用的。。很多人会卡到这里。。
- //取当前webBrowser登录后的Cookie值
- [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern bool InternetGetCookieEx(string pchUrl, string pchCookieName, StringBuilder cookieData, ref uint datasize, int dwFlags, IntPtr lpReserved);
- //取出Cookie,当登录后才能取
- private static string GetCookieString(string url)
- {
- uint datasize = 256;
- StringBuilder cookieData = new StringBuilder((int)datasize);
- if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x2000, IntPtr.Zero))
- {
- if (datasize < 0)
- {
- return null;
- }
- cookieData = new StringBuilder((int)datasize);
- if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x2000, IntPtr.Zero))
- {
- return null;
- }
- }
- return cookieData.ToString();
- }
复制代码 |
|