主页 > 编程资料 > C# >
发布时间:2014-10-08 作者:网络 阅读:208次
private string HttpPost(string Url, string postDataStr)         {             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);             request.Method = "POST";             request.ContentType = "application/x-www-form-urlencoded";             request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);             request.CookieContainer = cookie;             Stream myRequestStream = request.GetRequestStream();             StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));             myStreamWriter.Write(postDataStr);             myStreamWriter.Close();               HttpWebResponse response = (HttpWebResponse)request.GetResponse();               response.Cookies = cookie.GetCookies(response.ResponseUri);             Stream myResponseStream = response.GetResponseStream();             StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));             string retString = myStreamReader.ReadToEnd();             myStreamReader.Close();             myResponseStream.Close();               return retString;         }           public string HttpGet(string Url, string postDataStr)         {             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);             request.Method = "GET";             request.ContentType = "text/html;charset=UTF-8";               HttpWebResponse response = (HttpWebResponse)request.GetResponse();             Stream myResponseStream = response.GetResponseStream();             StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));             string retString = myStreamReader.ReadToEnd();             myStreamReader.Close();             myResponseStream.Close();               return retString;         }

C#模拟get和post

转:http://www.cnblogs.com/xssxss/archive/2012/07/03/2574554.html
关键字词: