Last post Nov 21, 2019 01:03 PM by uid250511
Nov 21, 2019 12:45 PM|uid250511|LINK
HttpWebRequest hWR = (HttpWebRequest)WebRequest.Create(Url);
Uri uri = new Uri(Url);
hWR.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
hWR.ContentType = "application/json";
hWR.Method = "POST";
hWR.KeepAlive = true;
byte data = Encoding.UTF8.GetBytes(UsernamePassword); // I dont know if this is correct or not, Im just passing in the credentials in JSON format which contains no parameters as such
hWR.ContentLength = data.Length; // Again i dont know if this is correct or not
using (var stream = hWR.GetRequestStream())
using (GZipStream compressionStream = new GZipStream(stream, CompressionMode.Compress, true))
compressionStream.Write(data, 0, data.Length);
var response = (HttpWebResponse)hWR.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
catch (Exception ex)
I receive no error if i have the following within the Stream code
stream.Write(data, 0, data.Length);
but the issue i come across is that the response is encoded, i can verify this by looking at the request in a web monitoring tool and decoding it, which shows the data.
So i added the GZipStream Using statement but i get a range of errors but the current one is "The base stream is not readable.\r\nParameter name: stream" or
"was expecting xx content length but received xx"
How could i decode the response?
Nov 21, 2019 01:03 PM|uid250511|LINK
Knew this would happen. Found the answer after i post the question.
Remove the Gzip compression code and add this at the start of the request
httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;