I'm building a client for an RSS reading service. I'm using the RestSharp library to interact with their API.
The API states:
When creating or updating a record you must set
application/json;charset=utf-8
as theContent-Type
header.
This is what my code looks like:
RestRequest request = new RestRequest("/v2/starred_entries.json", Method.POST);
request.AddHeader("Content-Type", "application/json; charset=utf-8");
request.RequestFormat = DataFormat.Json;
request.AddParameter("starred_entries", id);
//Pass the request to the RestSharp client
Messagebox.Show(rest.ExecuteAsPost(request, "POST").Content);
However; the service is returning an error
Error 415: Please use the 'Content-Type: application/json; charset=utf-8' header
Why isn't RestSharp passing the header?
Here is the solution
http://restsharp.blogspot.ca/
Create a json object with same name properties and set the values (Make sure they are similar to those of name value pair for post request.)
After that use default httpclient.
In version 105.2.3.0 I can solve the problem this way:
Old question but still top of my search - adding for completeness.
Although this is a bit old: I ran into the same problem.. seems some attributes such as "content-type" or "date" cannot be added as parameter but are added internally. To alter the value of "content-type" I had to change the serialzer setting (altough I didn`t use it because I added a json in the body that was serialized before!)
as soon as I did this the header showed up as intended:
You most probably run into this problem: https://github.com/restsharp/restsharp/issues/221 There is a working solution to your problem @ http://itanex.blogspot.co.at/2012/02/restsharp-and-advanced-post-requests.html
The solution provided on my blog is not tested beyond version 1.02 of RestSharp. If you submit a comment on my answer with your specific issue with my solution, I can update it.