private static byte[] readBody(HttpWebResponse response) { if (response.ContentLength != 0) { byte[] body = null; var respStream = response.GetResponseStream(); #if NETSTANDARD1_1 var contentEncoding = response.Headers["Content-Encoding"]; #else var contentEncoding = response.ContentEncoding; #endif if (contentEncoding == "gzip") { using (var decompressed = new GZipStream(respStream, CompressionMode.Decompress, true)) { body = HttpUtil.ReadAllFromStream(decompressed); } } else if (contentEncoding == "deflate") { using (var decompressed = new DeflateStream(respStream, CompressionMode.Decompress, true)) { body = HttpUtil.ReadAllFromStream(decompressed); } } else { body = HttpUtil.ReadAllFromStream(respStream); } respStream.Dispose(); if (body.Length > 0) { return(body); } else { return(null); } } else { return(null); } }
private static byte[] readBody(HttpWebResponse response) { if (response.ContentLength != 0) { var body = HttpUtil.ReadAllFromStream(response.GetResponseStream()); if (body.Length > 0) { return(body); } else { return(null); } } else { return(null); } }
private static byte[] readBody(HttpWebResponse response) { return(HttpUtil.ReadAllFromStream(response.GetResponseStream(), (int)response.ContentLength)); }