protected string HttpGet(string uri) { string hoststr = uri.Replace("https://", "").Replace("http://", ""); Task <HttpResponseMessage> task; lock (context_lock) { hoststr = hoststr.Substring(0, hoststr.IndexOf("/")); _client.DefaultRequestHeaders.Host = hoststr; _client.DefaultRequestHeaders.Referrer = new Uri(uri.Replace("/cat/json", "").Replace(xiamiUrl, playUrl)); task = _client.GetAsync(uri); } var result = task.Result; if (result.Content.Headers.ContentEncoding.Contains("gzip")) { var rawResult = result.Content.ReadAsByteArrayAsync().Result; var finResult = GZipHelper.Decompress_GZip(rawResult); return(Encoding.UTF8.GetString(finResult)); } return(result.Content.ReadAsStringAsync().Result); }
protected string HttpPost(string uri, FormUrlEncodedContent content) { content.Headers.Add("Referer", uri.Replace("/cat/json", "").Replace(xiamiUrl, playUrl)); var result = _client.PostAsync(uri, content).Result; if (result.Content.Headers.ContentEncoding.Contains("gzip")) { var rawResult = result.Content.ReadAsByteArrayAsync().Result; var finResult = GZipHelper.Decompress_GZip(rawResult); return(Encoding.UTF8.GetString(finResult)); } return(result.Content.ReadAsStringAsync().Result); }