http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 26440|回复: 17

[例子] webBrowser获取取Cookie不全的解决方法

[复制链接]
发表于 2013-1-21 11:02:33 | 显示全部楼层 |阅读模式
我这里有一个方法,只要你加到自己的程序里面,然后直接调用就行了
[C#] 纯文本查看 复制代码
//取当前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();
        }

获取的方法很简单
[C#] 纯文本查看 复制代码
string ccokie= GetCookieString("http://www.sufeinet.com");


本帖被以下淘专辑推荐:



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-10-16 19:29:51 | 显示全部楼层
报错啊   
这一行   if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
怎么解决啊
Form2::InternetGetCookieEx' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
发表于 2013-1-21 19:46:25 | 显示全部楼层
已阅,顶一下
 发表于 2013-2-1 06:56:07
转播微博
发表于 2013-5-1 11:59:14 | 显示全部楼层
真是难得给力的帖子啊,强烈支持楼主。
发表于 2013-8-21 05:16:08 | 显示全部楼层
直接从DLL里GetProcAddress把这两个函数扒出来,然后定义这个值为0x00002000使用
发表于 2013-8-28 03:36:22 | 显示全部楼层
不错,看看。
回复

使用道具 举报

发表于 2014-6-13 14:28:04 | 显示全部楼层
为什么要调用2次 InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null)
发表于 2014-6-24 22:55:21 来自移动端 | 显示全部楼层
留名 很高级的样子
发表于 2014-10-17 10:01:47 | 显示全部楼层
不错,帮顶。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-19 13:40

© 2014-2021

快速回复 返回顶部 返回列表