|
本帖最后由 格林童话 于 2013-5-12 18:22 编辑
前几天在论坛发过个帖子,使用中POST登陆腾讯网返回异常问题,
研究了几天,发现 httphelper类登陆腾讯网站返回的Cookies 很多重复,并且有字符","(英文逗号),登陆后返回的Cookies 是:
pt2gguin=o1284051084; EXPIRES=Fri, 02-Jan-2020 00:00:00 GMT; PATH=/; DOMAIN=qq.com;,superuin=o1284051083; PATH=/; DOMAIN=ptlogin2.qq.com; HttpOnly,superkey=5arfJIUPnF9orGf0cIPIPC8dj6CAHPoTNTdvwDtRd0J_; PATH=/; DOMAIN=ptlogin2.qq.com; HttpOnly,uin=o1284051083; PATH=/; DOMAIN=qq.com;,skey=@Uvvuegilr; PATH=/; DOMAIN=qq.com;,ETK=; PATH=/; DOMAIN=ptlogin2.qq.com;,ptisp=ctc; PATH=/; DOMAIN=qq.com;,RK=ZDAGU8QOz4; EXPIRES=Wed, 10-May-2023 09:26:26 GMT; PATH=/; DOMAIN=qq.com;,ptuserinfo=266e6273703b; PATH=/; DOMAIN=ptlogin2.qq.com;,ptcz=2498ee8af93eac52dd70b103f51201c8ffc748a8a3881062f8e02b5eb0d805fc; EXPIRES=Fri, 02-Jan-2020 00:00:00 GMT; PATH=/; DOMAIN=ptlogin2.qq.com;,airkey=; EXPIRES=Fri, 02-Jan-1970 00:00:00 GMT; PATH=/; DOMAIN=qq.com;
像如果要使用这样的Cookies 未经处理要继续操作返回结果会是“未登录”,腾讯返回未登录原因只会是Cookies验证失败。
抛开httphelper类,我使用另一个方法,返回的Cookie正常:
public static string HttpGet(string Url, string Cookies, ref string Cookie, string Proxy, string Referer, int Time, bool Bool)
{
try
{
CookieContainer cookie = new CookieContainer();
HttpWebRequest HttpWeb = (HttpWebRequest)HttpWebRequest.Create(Url);
HttpWebResponse WebResponse;
if (Proxy != "")
{
WebProxy proxy = new WebProxy(Proxy, true);
HttpWeb.Proxy = proxy;
}
else
{
HttpWeb.Proxy = null;
}
Uri Site = new Uri(Referer);
string[] Array = Regex.Split(Cookies, ";");
foreach (string Sarray in Array)
{
cookie.SetCookies(Site, Sarray.ToString());
}
HttpWeb.Timeout = Time;
HttpWeb.AllowAutoRedirect = Bool;
HttpWeb.MaximumAutomaticRedirections = 5;
HttpWeb.ContentType = "application/x-www-form-urlencoded";
HttpWeb.UserAgent = "Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413";
HttpWeb.Referer = Referer;
HttpWeb.CookieContainer = cookie;
HttpWeb.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
HttpWeb.Method = "GET";
WebResponse = (HttpWebResponse)HttpWeb.GetResponse();
HttpWeb.KeepAlive = true;
string Cotent = new StreamReader(WebResponse.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
HttpWeb.Abort();
WebResponse.Close();
foreach (Cookie ck in WebResponse.Cookies)
{
Cookie += ck.Name + "=" + ck.Value + "; ";
}
return Cotent;
}
方法返回的Cookie是:
confirmuin=0; ptisp=ctc; verifysession=h00af3b5e418fdf6766c3b3d645dfff5d8109d8f4b4da259eae30d16fbec19a5b6a1cbb8a360d671680d5c83fb9f2cba45c; pt2gguin=o2848861676; superuin=o2848861676; superkey=IaWAhj*vygP5WyLW4B7gQxBq*9EPHzFbxAbBK8Evqa8_; uin=o2848861677; skey=@41H5cZ6QDJ; ETK=; RK=Z3AXeh867k; ptuserinfo=6166656661776566; ptcz=db405f7a11ed26b76b0d87d63e14e5ba2e0d5ca9d2570561f2df9571926d8380; airkey=;
(没有英文逗号,没有重复Cookie,仅供参考)
我的意思是使用httphelp类中,返回Cookie存在无效字符跟重复Cookie,处理起来比较头疼,
刚学C# 很多问题比较菜鸟,大鸟勿喷,希望在腾讯方面有研究的大牛指教,、
上个帖子的链接: http://www.sufeinet.com/forum.php?mod=viewthread&tid=3076&extra=page%3D1&page=1&
(里面附GET成功登陆腾讯微博跟使用httphelp返回Cookie提交开通微博返回:未登录 源码 附件在该贴6楼)
|
|