标签:
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