httpwebrequest获取cookie不全的问题(有图有代码,目前无易做图...)
网址:http://tuiguang.ganji.com/house_report/auth.php我用httpwatch跟踪有7个cookie,而用httpwebrequest只能得到2个,不知道为啥,哪位帮个忙???
我只能得到 jsession 和 nsc_wt_uh_qpsu_80 ,连wt_fpc都得不到,很奇怪...
补充一下,我清了一下cookie,发现默认不是7个,是三个,但我的request还是只能得到两个,这个没有得到 __utmc Sent 32156897 / ganji.com (Session) 貌似跟域名有关系,但是我不知道怎么得到这个(ganji.com)域名下的cookie.
HttpWebRequest request;
HttpWebResponse response = null;
request = WebRequest.Create("http://tuiguang.ganji.com/house_report/auth.php") as HttpWebRequest;
request.CookieContainer = cookie;
request.Method = "GET";
request.Timeout = 30000;
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Alexa Toolbar)";
request.Accept = "*/*";
request.Referer = url;
//request.Headers.Add("Accept-Language", "zh-CN");
//request.Headers.Add("Accept-Encoding", "gzip, deflate");
request.KeepAlive = true;
try
{
//获取服务器返回的资源
using (response = (HttpWebResponse)request.GetResponse())
{
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
// request.Headers.Remove("Cookie");
string cookieHeader = request.CookieContainer.GetCookieHeader(request.Address);
if (cookieHeader.Length > 0)
{
request.Headers["Cookie"] = cookieHeader;
}
if (response.Cookies.Count > 0)
{
cookie.Add(response.Cookies);
}
}
}
}
catch
{
}
--------------------编程问答-------------------- --------------------编程问答-------------------- 上去啊..... --------------------编程问答-------------------- --------------------编程问答-------------------- 我也是,那些参数咋加上去呢? --------------------编程问答-------------------- 那几个cookie是通过一个JS文件里设置的,也不是必须的,不用理会
补充:.NET技术 , C#