2014-12-21 71 views
0

我想登錄到我的Gmail帳戶並更改密碼100次以將其設置爲舊密碼。 (正如你知道谷歌保持100個以前的密碼的歷史,並不讓你選擇其中之一)。 我正在使用HttpWebRequest和HttpWebResponse來解決我的問題。並且我在Fiddler中監視了請求和響應。 但是,當我用以下代碼登錄到Gmail時,我沒有收到任何cookie。 問題在哪裏?使用HttpWebRequest登錄到Gmail沒有接收到cookie

  HttpWebRequest http = WebRequest.Create("https://accounts.google.com/ServiceLoginAuth") as HttpWebRequest; 
     http.KeepAlive = true; 
     http.Host = "accounts.google.com"; 
     http.CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAge, new TimeSpan(0)); 
     http.Referer = "https://accounts.google.com/ServiceLogin?sacu=1&scc=1&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&hl=en&service=mail"; 
     http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; 
     http.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"; 
     http.Method = "POST"; 
     http.ContentType = "application/x-www-form-urlencoded"; 
     string postData = ""; 
     postData += "GALX=" + "qpld0kUdZuc"; 
     postData += "&continue=" + "https://mail.google.com/mail/"; 
     postData += "&service=" + "mail"; 
     postData += "&rm=" + "false"; 
     postData += "&itmpl=" + "default"; 
     postData += "&hl=" + "en"; 
     postData += "&scc=" + "1"; 
     postData += "ss=" + "1"; 
     postData += "&sacu=" + "1"; 
     postData += "&_utf8=" + "☃"; 
     postData += "&bgresponse=" + "!A0L90r-qE6ZLyUQ7tYD_B09KGgIAAAAjUgAAAAcqARcN5-HZ6OMO9yMKHpX_wJvfu81b67CyiAbn0EbvzuV9yjTly_ZM6err6uAruVCVnx5qUodg7vq6PIaYWpBtVnOzc2Ean-7ITFxt4SqBb0VAKLOJElXwWmximH-oydxBVH05VR4xLmWF1D00_yiPaXcqibx8ihD8yB1e8bOWrmfdzuVgyOfImv1LTSATv-AMI2W0dfTJlWmmngo4yefWiIEAYHJwixpArol4gDtxBAW81W98CMyXPNxXyu3JV3mCUMSrCh1EPJAX3DpfrU7bmD1O-gO7p8Gw5qU1vAuYt61AaLC9ydABYpvd3oysvccseXDdXJEI9fpeoOV8TNc3QvLYarUPbtjG1gYxgMh_zY72ogVucxCoj8U"; 
     postData += "&pstMsg=" + "1"; 
     postData += "&dnConn=" + ""; 
     postData += "&checkConnection=" + ""; 
     postData += "&checkedDomains=" + "youtube"; 
     postData += "&Email=" + "myEmailAddress"; 
     postData += "&Passwd=" + "my password"; 
     postData += "&signIn=" + "Sign in"; 
     postData += "&PersistentCookie=" + "yes"; 
     byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData); 
     http.ContentLength = dataBytes.Length; 
     using (Stream postStream = http.GetRequestStream()) 
     { 
      postStream.Write(dataBytes, 0, dataBytes.Length); 
     } 
     HttpWebResponse httpResponse = http.GetResponse() as HttpWebResponse; 
     // Probably want to inspect the http.Headers here first 
     http = WebRequest.Create("https://accounts.google.com/b/0/EditPasswd") as HttpWebRequest; 
     http.CookieContainer = new CookieContainer(); 
     http.CookieContainer.Add(httpResponse.Cookies); 

回答