想做一個登陸小米網站的程序,在使用post模擬登陸的時候,能夠獲取到登陸後的cookie,cookieContainer裡面有3個域名。(.xiaomi.com)(account.xiaomi.com)(.account.xiaomi.com) 在.account.xiaomi.com中存在著關鍵的cookie,pwdToken和passToken都有存在著。但是使用這個cookieContainer,然後httpWebRequest的時候,用get方法獲取https://account.xiaomi.com/pass/userInfo?userId=73896043 的時候,我用fiddler發現他只發送了account.xiaomi.com域名中的cookie,而沒有發送.account.xiaomi.com中的cookie。導致進頁面被認為沒登陸,一直返回登陸頁面。第一次做winform的程序,被這個問題困擾了好多天了,一直沒能解決。
使用ie登陸的話,用httpwatch能看到他發送了.account.xiaomi.com中的cookie,為什麼使用程序get的時候他就不發送.account.xiaomi.com中的cookie了。甚為糾結。。。
希望各位大大指點迷津。。。讓我不要再糾結了。。。
private HttpWebResponse loginResponse;
private StreamReader loginRespReader;
private CookieContainer m_Cookie = new CookieContainer();
private void button1_Click(object sender, EventArgs e)
{
this.xiaomiLogin();
string str=this.loginRespReader.ReadToEnd();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://account.xiaomi.com/pass/userInfo?userId=174314059");
req.CookieContainer = new CookieContainer();
req.CookieContainer = m_Cookie;
req.Method = "GET";
//req.ContentType = "application/x-www-form-urlencoded";
loginResponse = (HttpWebResponse)req.GetResponse();
loginRespReader = new StreamReader(loginResponse.GetResponseStream());
textBox1.Text = loginRespReader.ReadToEnd();
}
private void xiaomiLogin()
{
string requestUriString = "https://account.xiaomi.com/pass/serviceLoginAuth2";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUriString);
request.CookieContainer = new CookieContainer();
request.CookieContainer = m_Cookie;
request.Method = "POST";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
string s = this.quoteParas(paras);
byte[] bytes = Encoding.UTF8.GetBytes("passToken=&user=13763114744&pwd=xiaomi123&callback=https%3A%2F%2Faccount.xiaomi.com&sid=passport&qs=%253Fsid%253Dpassport&hidden=&_sign=KKkRvCpZoDC%2BgLdeyOsdMhwV0Xg%3D");
request.ContentLength = bytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
this.loginResponse = (HttpWebResponse)request.GetResponse();
m_Cookie = request.CookieContainer;
this.loginRespReader = new StreamReader(this.loginResponse.GetResponseStream());
}
tring requestUriString = "https://account.xiaomi.com/pass/serviceLoginAuth2";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUriString);
request.CookieContainer = new CookieContainer();
request.CookieContainer = m_Cookie;
request.Method = "POST";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
string s = this.quoteParas(paras);
byte[] bytes = Encoding.UTF8.GetBytes("passToken=&user=13763114744&pwd=xiaomi123&callback=https%3A%2F%2Faccount.xiaomi.com&sid=passport&qs=%253Fsid%253Dpassport&hidden=&_sign=KKkRvCpZoDC%2BgLdeyOsdMhwV0Xg%3D");
request.ContentLength = bytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
this.loginResponse = (HttpWebResponse)request.GetResponse();
m_Cookie = request.CookieContainer;
this.loginRespReader = new StreamReader(this.loginResponse.Get