最新发布 C# 后台获取http请求的数据

发布时间: 2022-12-30,浏览量:496
string url = "http://api.huceo.com/wxnew"; 

string param = "key=apikey&num=10" ;

public static string request(string url, string param)
        {
            string strURL = url + '?' + param;
            System.Net.HttpWebRequest request;
            request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
            request.Method = "GET";
            // 添加header
            //request.Headers.Add("apikey", APIKey);
            System.Net.HttpWebResponse response;
            response = (System.Net.HttpWebResponse)request.GetResponse();
            System.IO.Stream s;
            s = response.GetResponseStream();
            string StrDate = "";
            string strValue = "";
            StreamReader Reader = new StreamReader(s, Encoding.UTF8);
            while ((StrDate = Reader.ReadLine()) != null)
            {
                strValue += StrDate + "\r\n";
            }
            return strValue;
        }

热门文章 经典语录

热门文章 热门文章

查看更多