C# HttpWebReqeust和HttpWebResponse发送请求

   var request = (HttpWebRequest)WebRequest.Create("URL");

             var data = Encoding.UTF8.GetBytes("username=zhenjinggu&md5Pwd=643d1820b9ce49bbf283b4875848596c&otpCode=");

             request.Method = WebRequestMethods.Http.Post;
request.Timeout = * ;
request.AllowAutoRedirect = true;
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36";
var stream = request.GetRequestStream();
stream.Write(data, , data.Length);
stream.Close(); var response = (HttpWebResponse)request.GetResponse();
var sr = new StreamReader(response.GetResponseStream());
var content = sr.ReadToEnd();
上一篇:在MVC3中使用code first生成数据局库并操作数据库


下一篇:Socket网络编程--FTP客户端