.net发送HTTP请求

2021-02-02 14:14

阅读:641

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


评论


亲,登录后才可以留言!