苏飞论坛

标题: 问下如何获取webbrowser的sessionid? [打印本页]

作者: hhbkiller    时间: 2017-12-2 01:12
标题: 问下如何获取webbrowser的sessionid?
遇到个需求在webbrowser中登录,然后需要获取cookie使用httprequesr模拟后续操作,然而现在卡在无论如何获取webbrowser的cookie,都不能取到其中的sessionid这个值,使用抓包软件显示有这个值,但是写代码取无论如何取不到,使用了诸多方式都不行,为何抓包软件可以取到呢?查遍百度三年前就有人问现在都无人能搞定,求教大神指点迷津

作者: hhbkiller    时间: 2017-12-2 18:23
没人能解答一下吗
作者: hhbkiller    时间: 2017-12-2 18:25
飞哥求救啊,如果说自带的webbrowser不可以,是否有可以获取到sessionid的版本?
作者: 站长苏飞    时间: 2017-12-4 09:01
[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();
        }


作者: hhbkiller    时间: 2017-12-4 12:34
飞哥这个就是我正在用的代码,就是不能获取sessionid,其它部分都有
作者: hhbkiller    时间: 2017-12-4 12:35
使用抓包工具看sessionid已经在cookie中了,但是自己写的代码就获取不到




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