苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

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

HttpHelper万能框架(V2.3) HttpHelper官方出品,无敌框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V1.9) 最牛的爬虫类,没有爬不到只有想不到 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 698|回复: 3

[HttpHelper] 【HttpHelper 的問題???】

[复制链接]
发表于 2018-4-11 20:38:11 | 显示全部楼层 |阅读模式
我之前問的
http://www.sufeinet.com/forum.ph ... ;tid=19731#lastpost
我後來就是用
webbrowser 認證成功後,將 cookie 給 CookieContainer
現在我想用 HttpHelper 去改寫
之前成功的代碼是

[C#] 纯文本查看 复制代码
private CookieContainer GetCookieContainer(string cookieStr)
{
CookieContainer myCookieContainer = new CookieContainer();
string[] cookstr = cookieStr.Split(';');
foreach (string str in cookstr)
{
string[] cookieNameValue = str.Split('=');
Cookie ck = new Cookie(cookieNameValue[0].Trim().ToString(), cookieNameValue[1].Trim().ToString());
ck.Domain = "xxx.xxx.xxx";
myCookieContainer.Add(ck);
}

return myCookieContainer;
}

string cookieStr = webBrowser1.Document.Cookie;
cookies.Text = cookieStr;
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
webrequest.CookieContainer = GetCookieContainer(cookieStr);


我有2個問題
(1) 如果我要把 HttpWebRequest 改成 HttpHelper,要怎麼改寫(也就是說,HttpHelper要怎麼去接 CookieContainer)
(2) 如果我要把 webBrowser1.Document.Cookie 換成站長之前說的
[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();
}


請問要怎麼改寫
麻煩了
謝謝

发表于 2018-4-13 17:21:50 | 显示全部楼层
 楼主| 发表于 2018-4-16 17:45:29 | 显示全部楼层
我之前问的
http://www.sufeinet.com/forum.php?mod=viewthread&tid=19731#lastpost
我后来就是用
webbrowser 认证成功后,将 cookie 给 webrequest
现在我想用 把 webrequest 換成 HttpHelper 去改写
之前成功的代码是
[C#] 纯文本查看 复制代码
private CookieContainer GetCookieContainer(string cookieStr)
{
CookieContainer myCookieContainer = new CookieContainer();
string[] cookstr = cookieStr.Split(';');
foreach (string str in cookstr)
{
string[] cookieNameValue = str.Split('=');
Cookie ck = new Cookie(cookieNameValue[0].Trim().ToString(), cookieNameValue[1].Trim().ToString());
ck.Domain = "xxx.xxx.xxx";
myCookieContainer.Add(ck);
}
 
return myCookieContainer;
}
 
string cookieStr = webBrowser1.Document.Cookie;
cookies.Text = cookieStr;
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
webrequest.CookieContainer = GetCookieContainer(cookieStr);


我有1个问题
(1) 如果我要把 HttpWebRequest 改成 HttpHelper,要怎么改写(也就是说,HttpHelper 要怎么去接 CookieContainer)



请问要怎么改写
麻烦了
谢谢

 楼主| 发表于 2018-4-17 00:38:56 | 显示全部楼层
(2) 如果我要把webBrowser1.Document.Cookie换成站长之前说的

[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();
}


请问要怎么改写
麻烦了
谢谢

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

本版积分规则

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

GMT+8, 2019-3-18 21:47

© 2017-2018

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