首页 > 代码库 > c# 请求api获得json数据

c# 请求api获得json数据

public static string HttpGet(string Url)        {            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);            request.Proxy = null;            request.KeepAlive = false;            request.Method = "GET";            request.ContentType = "application/json; charset=UTF-8";            request.AutomaticDecompression = DecompressionMethods.GZip;            HttpWebResponse response = (HttpWebResponse)request.GetResponse();            Stream myResponseStream = response.GetResponseStream();            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);            string retString = myStreamReader.ReadToEnd();            myStreamReader.Close();            myResponseStream.Close();            if (response != null)            {                response.Close();            }            if (request != null)            {                request.Abort();            }            return retString;        }

 

c# 请求api获得json数据