日期:2014-05-18 浏览次数:20926 次
string url2 = "http://www.XXXX.com/user.php"; request = (HttpWebRequest)WebRequest.Create(url2 + "?" + new Random().NextDouble()); request.CookieContainer = container; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = param.Length; request.Method = "POST"; Stream myRequestStream = request.GetRequestStream(); StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312")); myStreamWriter.Write(param); //把数据写入HttpWebRequest的Request流 myStreamWriter.Close(); myRequestStream.Close(); //关闭打开对象 HttpWebResponse myHttpWebResponse = (HttpWebResponse)request.GetResponse(); //新建一个HttpWebResponse myHttpWebResponse.Cookies = container.GetCookies(request.RequestUri); //获取一个包含url的Cookie集合的CookieCollection Stream myResponseStream = myHttpWebResponse.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string outdata = myStreamReader.ReadToEnd(); //把数据从HttpWebResponse的Response流中读出 myStreamReader.Close(); myResponseStream.Close();