public async Task SendCleaningRequestAsync()
{
// Define el endpoint y datos
const string url = "https://teamaranto.com/gateway/Cleaning";
const string imagePath = "/Users/jasonsa/Downloads/cartoon-illustration-of-a-frog-vector.jpg";
// Verifica si el archivo existe antes de proceder
if (!File.Exists(imagePath))
{
Console.WriteLine("El archivo de imagen no existe: " + imagePath);
return;
}
// Usa "using" para liberar recursos automáticamente
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, url);
using var imageStream = File.OpenRead(imagePath);
// Crea el contenido del formulario
var content = new MultipartFormDataContent
{
{ new StringContent("1"), "comp_identifier" },
{ new StringContent("INICIO"), "Cleaning_type" },
{ new StringContent("ADMIN"), "advi_id" },
{ new StringContent("NO SE OBSERVA NADA"), "Cleaning_observation" },
{ new StringContent("3"), "Cleaning_Location_id" },
{ new StreamContent(imageStream), "CleaningImage", Path.GetFileName(imagePath) }
};
request.Content = content;
try
{
// Envía la solicitud y maneja la respuesta
var response = await client.SendAsync(request).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
// Imprime la respuesta
Console.WriteLine("Respuesta recibida:");
Console.WriteLine(responseContent);
}
catch (HttpRequestException ex)
{
Console.WriteLine("Error en la solicitud HTTP: " + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("Error general: " + ex.Message);
}
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎