How to decode response RRS feed

  • Question

  • User-284642143 posted
    	    HttpWebRequest hWR = (HttpWebRequest)WebRequest.Create(Url);
                Uri uri = new Uri(Url);
                hWR.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
                hWR.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-GB,en-US;q=0.9,en;q=0.8");
    			httpWebRequest.Headers.Add("Sec-Fetch-Site", "same-origin");
                httpWebRequest.Headers.Add("Sec-Fetch-Mode", "cors");
                hWR.Accept= "application/json";
                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?

    Thursday, November 21, 2019 12:45 PM

All replies

  • User-284642143 posted

    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;

    Thursday, November 21, 2019 1:03 PM