苏飞论坛

标题: 老大,那个webbrowser 获得COOKIES能不能做个例子 [打印本页]

作者: W@lf    时间: 2012-12-24 17:21
标题: 老大,那个webbrowser 获得COOKIES能不能做个例子
RT...

作者: 站长苏飞    时间: 2012-12-24 17:52
可以啊,其实就是一个方法,你直接调用就行了
[code=csharp]//取当前webBrowser登录后的Cookie值   
        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref int pcchCookieData, int dwFlags, object lpReserved);
        //取出Cookie,当登录后才能取   
        private static string GetCookieString(string url)
        {
            // Determine the size of the cookie      
            int datasize = 256;
            StringBuilder cookieData = new StringBuilder(datasize);
            if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
            {
                if (datasize < 0)
                    return null;
                // Allocate stringbuilder large enough to hold the cookie   
                cookieData = new StringBuilder(datasize);
                if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
                    return null;
            }
            return cookieData.ToString();
        }[/code]
原文中有的
http://www.sufeinet.com/thread-3-1-1.html

作者: W@lf    时间: 2012-12-24 20:49
没有指定webbrowser1..直接读取就行了。如果有多个webbrowser1呢
作者: W@lf    时间: 2012-12-24 22:04
有没有webbrowserHelper...
作者: 站长苏飞    时间: 2012-12-25 09:49
W@lf 发表于 2012-12-24 22:04
有没有webbrowserHelper...

这个没有,多个和这个没有关系吧,这个是根据URL获取的,只要是相同的URL Cookie都一样。
单独的也有cookie这个属性你可以看一下的
webBrowser1.Document.Cookie; 这就是直接获取的Cookie
作者: W@lf    时间: 2012-12-25 11:14
对 PInvoke 函数“rxlq!rxlq.helper.wbHelper::InternetGetCookieEx”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。

这个是什么原因。。老大
作者: 站长苏飞    时间: 2012-12-25 11:21
W@lf 发表于 2012-12-25 11:14
对 PInvoke 函数“rxlq!rxlq.helper.wbHelper::InternetGetCookieEx”的调用导致堆栈不对称。原因可能是托管 ...

这可能是你使用HTTPS的问题,HTTPS的会报这个错,但是不影响获取Cookie,你直接吃掉异常就行了。
一般你可以使用我上面写的[code=csharp]webBrowser1.Document.Cookie; [/code]来获取的
作者: W@lf    时间: 2012-12-26 23:28
苏飞老大,怎么把httphelper获取的带入webbrowser.
作者: 站长苏飞    时间: 2012-12-27 09:58
W@lf 发表于 2012-12-26 23:28
苏飞老大,怎么把httphelper获取的带入webbrowser.

直接把httphelper获取的Cookie给Webrowser就行了




欢迎光临 苏飞论坛 (http://www.sufeinet.com/) Powered by Discuz! X3.4