Friends I have to consume a web service from c #, this web service was developed by an external company which gave me the methods to test them, from the postman probe program the web service and it works well. Now in postman in the body I have the data to send in the form-data
My Query is how I can do to consume this web service from c #, I am trying to use Httpclienty I have the following
using (var client = new HttpClient())
{
// Establecer la url que proporciona acceso al servidor que publica la API
client.BaseAddress = new Uri("https://escuela.academi-cloud.net/ext_ws/integracion_escuela/actualizar_deuda_por_codigo");
// Configurar encabezados para que la petición de realice en formato JSON
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//Add headers
client.DefaultRequestHeaders.Add("api_key", "CSp1TqLIAe5PH1eIYEEmX6gItBYxt");
client.DefaultRequestHeaders.Add("codigo", "1162");
client.DefaultRequestHeaders.Add("valor_adeudado", "600");
client.DefaultRequestHeaders.Add("valores_pendientes", "[ { 'numero_factura': '001 - 001 - 00000001', 'fecha': '14 - 05 - 2020', 'monto_total': '500', 'detalles': [ { 'concepto': 'Pensión Enero 2018', 'valor': '200.89' }, { 'concepto': 'Pensión Febrero 2018', 'valor': '300.50' } ] } ]");
//Call client.PostAsJsonAsync to send a POST request to the appropriate URI
HttpResponseMessage resp = await client.PostAsync("",);
//This method throws an exception if the HTTP response status is an error code.
//var xx = resp.EnsureSuccessStatusCode();
if (resp.IsSuccessStatusCode)
{
}
else
{
var resultado = resp.Content.ReadAsStringAsync().Result;
// var result = JsonConvert.DeserializeObject<ResultServer>(resultado);
throw new Exception(string.Format("Message:{0}, ExceptionMessage: {1}", result.Message, result.ExceptionMessage));
}
// Obtener el texto JSON con los datos del login
string request = JsonConvert.SerializeObject(new
{
User = "usuario",
Password = "1234",
Secret_Id = "JGJHASDH7656775ASD776",
App_Id = "XXTYVFDR65432GBVCMNCBGDRT"
});
}
What I do not know is how to put in the content of the data in the client, and how to call the post method. If someone could help me, I'd appreciate it.
greetings