|
楼主 |
发表于 2013-5-9 12:29:23
|
显示全部楼层
- private void 执行登录方法()
- {
- string LoginURL = "http://caibian.cmed.org.cn/";
- //string cookiesss = "KOSSID=25b54d6d99d07b8c5d99fca193157324";
- //webBrowser1.Document.Cookie = cookiesss;
- webBrowser1.Navigate(LoginURL);
- MessageBox.Show("获取的cookies"+GetCookieString(LoginURL));
-
- }
- private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
- {
- MessageBox.Show(webBrowser1.Document.Cookie);
- }
- //取当前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();
- }
复制代码 抱歉,刚才发了 发现没有成功显示,我重新发了遍。
|
|