I'm trying to send json data with a REST POST request in Xamarin but no matter what i try I always get this error in response :
{ "message" : "Unexpected Content-Type 'application/x-www-form-urlencoded', expecting 'application/json'."}
I tested my request with this website : https://resttesttest.com/ and the response is ok with header set to "Content-Type", "application/json"
.
But within my code it's never working. I tried this method :
var request = new RestRequest("api/1/databases/{db}/collections/{coll}", Method.POST);
request.AddParameter("apiKey", Common.API_KEY);
request.AddUrlSegment("db", Common.DB_NAME);
request.AddUrlSegment("coll", collection);
request.AddHeader("Accept", "application/json");
request.AddParameter("application/json", JsonConvert.SerializeObject(objet), ParameterType.RequestBody);
And this one :
var request = new RestRequest("api/1/databases/{db}/collections/{coll}", Method.POST);
request.AddParameter("apiKey", Common.API_KEY);
request.AddUrlSegment("db", Common.DB_NAME);
request.AddUrlSegment("coll", collection);
request.AddHeader("content-type", "application/json; charset=utf-8");
if (objet != null)
request.AddJsonBody(objet);
And many other but no mater what i do I always get the same response.