I'm testing WSO2 Api Manager.
I have some Apis working good and wow I need to integrate them with Api Manager 2.6.0. I've make some test and all Get requests work very good, but when I make Post Request sometimes failed. For some reason the parameters from body are nulls, another times the parameters are received by the APIs.
However if I make the requests without Api Manager, they all work good all the time.
My APIs are developed in .Net Web Api 2.0.
This is my code to call APIs, I make some test with HttpClient and RestSharp getting the same result. However when I test using Postman, the APIS always work good, event through the API Manager.
Example using HttpClient:
public async Task PostHttpClient(TarificacionParametros entidad, string url)
{
var personaJson = JsonConvert.SerializeObject(entidad);
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Clear();
//httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", BEARER);
HttpContent httpContent = new StringContent(personaJson, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = httpClient.PostAsync(url, httpContent).Result;
if (response.IsSuccessStatusCode)
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<object>(responseBody);
}
}
Example using Restsharp:
public async Task PostRestSharp(TarificacionParametros entidad, string url)
{
var client = new RestClient(url);
var request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(entidad);
Console.WriteLine(entidad.Capital);
// easily add HTTP Headers
request.AddParameter("Authorization", "Bearer " + BEARER, ParameterType.HttpHeader);
var response = client.Execute<object>(request);
}
Note: I don't post API's code because they are good, they have time working with any problem in production, now we just need to integrate them with WSO2 Api Manager.
Regards