What's the correct way to POST a compressed JSON string with RestSharp?
Posted
by
Steve Dunn
on Stack Overflow
See other posts from Stack Overflow
or by Steve Dunn
Published on 2012-12-14T17:01:16Z
Indexed on
2012/12/14
17:03 UTC
Read the original article
Hit count: 1516
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?
© Stack Overflow or respective owner