What's the correct way to POST a compressed JSON string with RestSharp?
- by Steve Dunn
I want to use RestSharp to POST something somewhere. I'm posting straight JSON (and not POCOs). Because I'm posting plain JSON, I believe I need to use this workaround instead of setting Body:
request.AddParameter(
"application/json", myJsonString, ParameterType.RequestBody);
This works fine when I'm not compressing the JSON. When I do, using this:
request.Headers.Add("Content-Encoding", "gzip");
request.AddParameter(
"application/json",
GZipStream.CompressString(myJsonString),
ParameterType.RequestBody);
This doesn't work. I stepped through the code and in RestClient::ConfigureHttp, I see:
http.RequestBody = body.Value.ToString();
Since I'm giving at a byte array, body.Value is set to System.Byte[]
Is there a way for RestSharp to handle a gzipped json string in a POST request?