Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>svick's comment is right. Set the content type in the first parameter of <code>AddParameter()</code> and you can leave out the <code>AddHeader()</code> call.</p> <p>While that's the 'right' answer, I'll explain why it has a confusing method for doing this that's not exactly obvious.</p> <p>The intended way to accomplish this is to use <code>AddBody()</code> along with <code>RestRequest.RequestFormat</code>. An example:</p> <pre><code>var client = new RestClient(); // client.XmlSerializer = new XmlSerializer(); // default // client.XmlSerializer = new SuperXmlSerializer(); // can override with any implementaiton of ISerializer var request = new RestRequest(); request.RequestFormat = DataFormat.Xml; request.AddBody(objectToSerialize); </code></pre> <p>The serialization of <code>objectToSerialize</code> is based on the registered <code>XmlSerializer</code>. If you use <code>RequestFormat = DataFormat.Json</code>, then the <code>RestClient.JsonSerializer</code> is used. Implementations of <code>ISerializer</code> (which you can use to override the default serialization) declare their own Content-Types which is what gets passed through the janky <code>AddParameter()</code> overload you're using.</p> <p><code>AddParameter(contentType, content, ParameterType.RequestBody)</code> was never meant to be called directly. It was added as a workaround to pass though data from <code>AddBody()</code> but then other things became dependent on it so it stuck around. It was a terrible decision in hindsight but it's too late to change it in the 1xx version line. If I ever build another version I'll make this more obvious.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload