RestSharp does not seem to allow me to override the Content-Type for the mail request. I followed the directions we found here to no avail. I also tried manually setting the content type of the header to application / json via request.AddHeaders ("content-type", "application / json");
Examples of query execution:
private IRestResponse ExecuteRequest<T>(string resource, Method method, T model) { var client = CreateRestClient(); var request = new RestRequest(resource, method) { RequestFormat = DataFormat.Json }; var json = JsonConvert.SerializeObject(model); request.AddHeader("Accept", "application/json"); request.AddHeader("User-Agent", "Fiddler"); request.Parameters.Clear(); request.AddParameter("auth_token", _apiKey); request.AddParameter("application/json", json, ParameteType.RequestBody); return client.Execute(request); }
Error message:
{ "error": { "code": 400, "message": "The request requires a properly encoded body with the 'content-type' header set to '['application/json']", "type": "Bad Request" } }
Fiddler request source data:
POST **omitted** HTTP/1.1 Accept: application/json, application/xml, text/json, text/x-json,text/javascript, text/xml User-Agent: RestSharp/105.0.1.0 Content-Type: application/x-www-form-urlencoded Host: **omitted** Content-Length: 51 Accept-Encoding: gzip, deflate Connection: Keep-Alive
As you can see, the Content-Type request is still the application / x -www-form-urlencoded. Any ideas? (thanks in advance)
source share