模拟Get请求

Posted on 2018-09-20 10:44  杭州丑八怪  阅读(125)  评论(0编辑  收藏  举报
public static string GetGat(string url)
        {
            string test = string.Empty;
            using (var httpClient = new HttpClient())
            {
                HttpResponseMessage response = httpClient.GetAsync(new Uri(url)).Result;
                string result = response.Content.ReadAsStringAsync().Result;
                test = result;
            }
            return test;
        }

nuget下载HttpClient,

引用using System.Net.Http;