32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using System.Net;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
|
|
public class HttpClientService
|
|
{
|
|
private readonly HttpClient _client;
|
|
|
|
public HttpClientService()
|
|
{
|
|
var handler = new HttpClientHandler
|
|
{
|
|
ClientCertificates = { new X509Certificate2("X:\\Back\\APP Smart\\Certificado\\cert_ssl.pfx", "appsmart") },
|
|
|
|
//// Configura o proxy do Fiddler
|
|
//Proxy = new WebProxy("127.0.0.1", 8888),
|
|
//UseProxy = true,
|
|
|
|
//// Permite qualquer certificado SSL (para evitar erros com o proxy do Fiddler)
|
|
//ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
|
|
};
|
|
_client = new HttpClient(handler) { DefaultRequestHeaders = { { "SOAPAction", "listarPLD" } } };
|
|
}
|
|
|
|
public async Task<string> EnviarRequisicaoAsync(string xmlRequest)
|
|
{
|
|
var content = new StringContent(xmlRequest, Encoding.UTF8, "application/json");
|
|
var response = await _client.PostAsync("https://servicos.ccee.org.br:443/ws/prec/PLDBSv1", content);
|
|
return await response.Content.ReadAsStringAsync();
|
|
}
|
|
}
|