I have been using AddParameter
to include XML bodies in my HTTP requests:
request.AddParameter(contentType, body, ParameterType.RequestBody);
>
I had the same issue. Turned out that RestSharp behaves in a little odd way.
NOT WORKING:
request.Parameters.Add(new Parameter() {
ContentType = "application/x-www-form-urlencoded",
Type = ParameterType.RequestBody,
Value = bytes
});
WORKING (Add content-type as name):
request.Parameters.Add(new Parameter() {
Name = "application/x-www-form-urlencoded", // This is the 'funny' part
ContentType = "application/x-www-form-urlencoded",
Type = ParameterType.RequestBody,
Value = bytes
});
I tried this solution based on a comment here: https://github.com/restsharp/RestSharp/issues/901
which states "...name value will be used as Content-Type Header and contentType value will be ignored."
You dont have to add the value as the Content-Type parameter as well, but I fear that a future bug-fix might change the behaviour and then requiring the Content-Type to be used instead of name.