码迷,mamicode.com
首页 > Windows程序 > 详细

C# HttpWebReqeust和HttpWebResponse发送请求

时间:2016-03-16 16:48:36      阅读:480      评论:0      收藏:0      [点我收藏+]

标签:

 1   var request = (HttpWebRequest)WebRequest.Create("URL");
 2 
 3             var data = Encoding.UTF8.GetBytes("username=zhenjinggu&md5Pwd=643d1820b9ce49bbf283b4875848596c&otpCode=");
 4 
 5             request.Method = WebRequestMethods.Http.Post;
 6             request.Timeout = 60 * 1000;
 7             request.AllowAutoRedirect = true;
 8             request.ContentLength = data.Length;
 9             request.ContentType = "application/x-www-form-urlencoded";
10             request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
11             request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36";
12             var stream = request.GetRequestStream();
13             stream.Write(data, 0, data.Length);
14             stream.Close();
15 
16             var response = (HttpWebResponse)request.GetResponse();
17             var sr = new StreamReader(response.GetResponseStream());
18             var content = sr.ReadToEnd();

 

C# HttpWebReqeust和HttpWebResponse发送请求

标签:

原文地址:http://www.cnblogs.com/q975261413/p/5283803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!