
Hi,
I'm getting the errors below when I try to call a web service. Calling GET works fine, it just return the structure of webservice but when I try to call POST, I get always errors. What might be wrong with my code? It's C#.
public static async Task GetResponse(string token)
{
string body;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://example/namespaces/AXSF/api/services/ProjectServices/ProjectWbsService/getProjectInfo"),
Content = new FormUrlEncodedContent(new Dictionary
{
{ "company", "" },
{ "recordId", "" },
}),
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}
return body;
}
An exception occured when deserializing the request - Exception occured when parsing the request content - Unexpected character encountered while parsing value: c. Path '', line 0, position 0.".
What you should pass to the service operation is a JSON object. For example:
var contract = new { company = "", recordId = 0 };
string json = JsonConvert.SerializeObject(contract);