日期:2014-05-20  浏览次数:20836 次

HttpWebRequest 请求网页为什么拿不到返回cookie?求解啊!
本帖最后由 kangliangcheng 于 2013-09-03 16:51:21 编辑
为什么cookieContainer里面没有抓包工具抓到的cookie(roll_t_hd_thda=760bb74a5a0ee393bf73b70a3aa48cc2)呢?
代码:
StreamReader sr = null;
            HttpWebResponse response = null;
            HttpWebRequest request = null;
            Encoding encoding = System.Text.Encoding.GetEncoding("UTF-8");
            CookieContainer cookieContainer = new CookieContainer();
            Stream outstream = null;
            Stream instream = null;
            string content;
            string roll = "http://tc.hd.xiaomi.com/hdget?callback=hdcontrol";
            request = WebRequest.Create(roll) as HttpWebRequest;
            request.CookieContainer = cookieContainer;
            request.Method = "GET";           
            request.Host = "tc.hd.xiaomi.com";
            request.UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.11 Safari/537.36";
            response = (HttpWebResponse)request.GetResponse();
            instream = response.GetResponseStream();
            sr = new StreamReader(instream, encoding);

            content = sr.ReadToEnd();
            Uri urroll = new Uri(roll);

            if ((cookieContainer.GetCookieHeader(urroll).IndexOf("roll_t_hd_thda") < 0 ))
            {