I've got this Windows Phone 8 project in C#, where I'm using RestSharp 104.4.0 to make a request to a server. The server only accepts a "Accept" type of "application/json". My code to call the request:
var client = new RestClient(_jsonBaseUrl + someURL)
{
Authenticator = new HttpBasicAuthenticator(someUsername, somePassword)
};
var request = new RestRequest(Method.POST);
UTF8Encoding utf8 = new UTF8Encoding();
byte[] bytes = utf8.GetBytes(json);
json = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Accept", "application/json");
request.AddBody(json);
request.Parameters.Clear();
request.AddParameter("application/json", json, ParameterType.RequestBody);
client.ExecuteAsync<UserAccount>(request, response =>
{
if (response.ResponseStatus == ResponseStatus.Error)
{
failure(response.ErrorMessage);
}
else
{
success("done");
}
});
the "json" variable is a JSON string.
As you can see i've set my accept type to AddHeader("Accept", "application/json"); But for some wired reason the server receives this as accept type: "Accept": "application/json, application/xml, text/json, text/x-json, text/javascript, text/xml"
What do i have to do, to make sure the only accept type the server gets is "Accept": "application/json"?
Any kind of help would be much appreciated.
From https://groups.google.com/forum/#!topic/restsharp/KD2lsaTC0eM:
The Accept header is automatically generated by inspecting the "handlers" that are registered with the RestClient instance. One optin is to use RestClient.ClearHandlers (); and then add back explicitly the JSON deserializer with RestClient.AddHandler("application/json", new JsonDeserializer ());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With