日期:2014-05-18 浏览次数:21024 次
HttpWebRequest requestCookies = (HttpWebRequest)WebRequest.Create(要登入的某网址); requestCookies.ContentType = "application/x-www-form-urlencoded"; requestCookies.Referer = "要登入的某网址/login"; requestCookies.Headers.Set("Pragma", "no-cache"); requestCookies.Accept = "text/html, application/xhtml+xml, */*"; requestCookies.Headers.Set("Accept-Language", "zh-CN"); requestCookies.Headers.Set("Accept-Encoding", "gzip, deflate"); string temp = "PHPSESSID=22a234c094a7f36ba11e6d6767fc614c; cnzz_a30020080=0; sin30020080=; rtime30020080=0; ltime30020080=1330943336040; cnzz_eid30020080=78128217-1330939152-"; requestCookies.Headers.Set("cookie", temp); requestCookies.Method = "POST"; Encoding encoding23 = Encoding.GetEncoding("utf-8"); byte[] bytesToPost = encoding23.GetBytes("charset=utf-8&jumpurl=%2F&username=帐号&password=密码&rememberme=1&input2=%E7%99%BB+%E5%BD%95"); requestCookies.ContentLength = bytesToPost.Length; System.IO.Stream requestStream = requestCookies.GetRequestStream(); requestStream.Write(bytesToPost, 0, bytesToPost.Length); requestStream.Close(); HttpWebResponse hwr = (HttpWebResponse)requestCookies.GetResponse(); WebHeaderCollection head = hwr.Headers; IEnumerator iem = head.GetEnumerator(); ArrayList value = new ArrayList(); for (int i = 0; iem.MoveNext(); i++) { string key=head.GetKey(i); value.Add(head.GetValues(key)); } string filePath2 = @"c:\infor2.txt"; FileStream fs2 = new FileStream(filePath2, FileMode.Open, FileAccess.ReadWrite); StreamWriter sw2 = new StreamWriter(fs2); fs2.SetLength(0); for (int i = 0; i < value.Count; i++) { sw2.WriteLine(value[i].ToString()); } sw2.Close();