C# Get请求

一、WebClient发送http请求

         /// <summary>
        /// 使用WebClient 发送http请求
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string myWebCelin(string url)
        {
            WebClient clinet = new WebClient();
            clinet.Encoding = Encoding.UTF8;
            var result = clinet.DownloadString(url);

            return result;
        }

  

二、HttpWebRequest 发送Get请求

         /// <summary> 
        /// Get请求
        /// </summary> 
        public static string HttpGet()
        {
            string url = "你要请求的接口";
            string result = "";
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";


            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            Stream stream = response.GetResponseStream();
            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }
            return result;
        }

  

C# Get请求

上一篇:快速测试API接口生成接口文档


下一篇:如何关闭 windows 10 的边缘触控手势操作