public static async Task <JObject> HttpGet(String url) { initClient(); JObject jsonData = new JObject(); using (HttpResponseMessage response = await httpClient.GetAsync(url)) { if (response.StatusCode == HttpStatusCode.OK) { String strType = response.Content.Headers.ContentEncoding.ToString(); String strJson = ""; if (strType.Contains("gzip")) { byte[] byteArray = await response.Content.ReadAsByteArrayAsync(); strJson = ReadGzip(byteArray); } else { strJson = await response.Content.ReadAsStringAsync(); } jsonData = CoreAPI.Deserialize <JObject>(strJson); if (jsonData["result"] != null) { String code = jsonData["result"].ToString(); String msg = jsonData["msg"].ToString(); if (code != "0") { Logger.LogError("NetError" + code + msg + url); throw new Exception("NetError" + code + url); } } } else { String strError = response.StatusCode.GetHashCode().ToString() + "," + response.ReasonPhrase; Logger.LogError(strError); throw new Exception(strError); } } return(jsonData); }
public static async Task <JObject> HttpPost(JObject input, String url) { initClient(); JObject jsonData = new JObject(); HttpContent content = new StringContent(input.ToString(), Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await httpClient.PostAsync(url, content)) { if (response.StatusCode == HttpStatusCode.OK) { String strType = response.Content.Headers.ContentEncoding.ToString(); String strJson = ""; if (strType.Contains("gzip")) { byte[] byteArray = await response.Content.ReadAsByteArrayAsync(); strJson = ReadGzip(byteArray); } else { strJson = await response.Content.ReadAsStringAsync(); } jsonData = CoreAPI.Deserialize <JObject>(strJson); //String code = jsonData["result"].ToString(); //String msg = jsonData["msg"].ToString(); //if (code != "0") //{ // Logger.LogError("NetError" + code + msg + url); // throw new Exception(msg); //} } else { String strError = response.StatusCode.GetHashCode().ToString() + "," + response.RequestMessage; Logger.LogError(strError); throw new Exception(strError); } } return(jsonData); }