为什么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 ))
{
MessageBox.Show("没取到!");
}
fiddler抓包工具显示:
Response sent 112 bytes of Cookie data:
Set-Cookie: roll_t_hd_thda=760bb74a5a0ee393bf73b70a3aa48cc2; expires=Tue, 03-Sep-13 18:46:33 GMT; path=/; domain=.xiaomi.com
This response did not contain a P3P Header.
------解决方案--------------------
response.Cookies.Item["roll_t_hd_thda"]
上面那个只是传给服务端的 返回的在这个里面
------解决方案--------------------
去掉request.Host = "tc.hd.xiaomi.com";
------解决方案--------------------
就是用你的代码