码迷,mamicode.com
首页 > 其他好文 > 详细

C# 发送和接受Get请求

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

标签:style   blog   http   color   os   ar   div   sp   log   

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请求

标签:style   blog   http   color   os   ar   div   sp   log   

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

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