I've the following function but can't debug it because response never come. Service on the other side is working. Any help will be preciated, I can't deduce how must be do it with other answers in SO
public async Task<string> PostObjectToWebServiceAsJSON(object objectToPost, string validatorName, string method)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("myuri" + "/" + method);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// HTTP POST
var response = await client.PostAsJsonAsync("", objectToPost);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync();
}
else
{
string errplugin = "Error";
return null;
}
}
}
This is how I call it:
public PaymentResponseInternal Post(some stuff here)
{
Task<string> retornoPluginAsync = PostObjectToWebServiceAsJSON(some stuff here);
retornoPluginAsync.Wait();
string result = retornoPluginAsync.Result;
return JsonConvert.DeserializeObject<PaymentResponseInternal>(result);
}