VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • .net发送HTTP请求

 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();

相关教程