码迷,mamicode.com
首页 > Web开发 > 详细

.net发送HTTP请求

时间:2020-06-20 18:54:41      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:sts   oms   ons   urlencode   content   color   toe   amr   bytes   

 1 string postData = "appKey=" + appKey;//参数
 2 postData += ("&appSecret=" + appSecret);
 3 
 4 var request = (HttpWebRequest)WebRequest.Create(url);
 5 request.Method = "POST";//请求方式
 6 request.ContentType = "application/x-www-form-urlencoded";//请求内容类型
 7 var data = Encoding.UTF8.GetBytes(postData);//获取长度
 8  request.ContentLength = data.Length;
 9 Stream newStream = request.GetRequestStream();
10 
11  //send
12 newStream.Write(data, 0, data.Length);
13 newStream.Close();
14 
15 //get
16 WebResponse response = request.GetResponse();
17 newStream = response.GetResponseStream();
18 StreamReader reader = new StreamReader(newStream);
19 string responseFromServer = reader.ReadToEnd();//得到返回数据
20 reader.Close();
21 response.Close();

 

.net发送HTTP请求

标签:sts   oms   ons   urlencode   content   color   toe   amr   bytes   

原文地址:https://www.cnblogs.com/nevergiveup1115/p/13169428.html

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