HttpClient 获取json,即使返回状态不成功也返回json

        public static string HttpGet(string Url, string inStr, string token)
        {
            try
            {
                var requestUrl = Url + (inStr == "" ? "" : "?") + inStr;
                HttpClientHandler hch = new HttpClientHandler {Proxy = null, UseProxy = false};//设置代理为空 加快访问速度
                HttpClient client = new HttpClient(hch);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("token", token);
               var response = client.GetAsync(requestUrl).Result;
               var jsonString = response.Content.ReadAsStringAsync().Result;
               if (response.IsSuccessStatusCode)
               {
                   
               }
                return jsonString;
            }
            catch (Exception ex)
            {
                return "";
            }
        }
原文地址:https://www.cnblogs.com/simadi/p/14523954.html