RestSharp does not encode UTF-8 request

I am trying to send a request with one lonely parameter:

var client = new RestClient("");
var request = new RestRequest("whatever", Method.POST);
request.AddParameter("param", "");


This leads to the following request: notice the bunch of coded question marks:

Accept: application/json, application/xml, text/json, text/x-json, text/javascript, text/xml
User-Agent: RestSharp/
Content-Type: application/x-www-form-urlencoded
Content-Length: 24
Accept-Encoding: gzip, deflate



Imagine the sadness when the recipient receives these question marks.

How do I get RestSharp to properly encode the body as UTF-8, or how do I send the request in a RestSharp-friendly way so that it doesn't garble the data?


source to share

1 answer

Christer, this is the default encoding Content-Type: application/x-www-form-urlencoded

that uses ISO-8859-1 by default. If you specifically want to tell the server to expect UTF-8, you can add ; charset=UTF-8

at the end Content-Type: application/x-www-form-urlencoded ; charset=UTF-8

. But then it is your responsibility to ensure that the data you post is indeed UTF-8 encoded.

Or if you want to do it in "application / json" you can set the content type that way (I got this from ):

request.AddHeader("Accept", "application/json");
request.AddParameter("application/json", strJSONContent, ParameterType.RequestBody);


You can also use multipart/form-data

:<form action="YOUR_ACTION_NAME_HERE" method="post" enctype="multipart/form-data">



All Articles