首页 > 其他 > 详细

C# 发送和接受Get请求

时间:2014-09-18 18:40:04      阅读:373      评论:0      收藏:0      [点我收藏+]

1、发送Get请求

      public static string HttpGet(string Url, string postDataStr)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == string.Empty ? string.Empty : "?") + postDataStr);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }

2、接受Get请求

string str1 = HttpUtility.UrlDecode(this.Request.QueryString.ToString(), Encoding.UTF8);

 

C# 发送和接受Get请求

原文:http://www.cnblogs.com/tianxue/p/3979730.html

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