首页 > 其他 > 详细

C# 后台POST和GET 获取数据

时间:2014-06-14 08:48:58      阅读:681      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 private string PostData(string url, string postData)
 2 {
 3     ASCIIEncoding encoding = new ASCIIEncoding();
 4     byte[] data = encoding.GetBytes(postData);
 5     HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
 6 
 7     myRequest.Method = "POST";
 8     myRequest.ContentType = "application/x-www-form-urlencoded";
 9     myRequest.ContentLength = data.Length;
10     Stream newStream = myRequest.GetRequestStream();
11 
12     newStream.Write(data, 0, data.Length);
13     newStream.Close();
14 
15     HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
16     StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
17     string content = reader.ReadToEnd();
18     reader.Close();
19     return content;
20 }
21 
22 private string GetData(string url)
23 {
24     HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
25     myRequest.Method = "GET";
26     HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
27     StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
28     string content = reader.ReadToEnd();
29     reader.Close();
30     return content;
31 }
View Code

 

C# 后台POST和GET 获取数据,布布扣,bubuko.com

C# 后台POST和GET 获取数据

原文:http://www.cnblogs.com/kkwoo/p/3787835.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!