require 'openssl' require 'faraday' request_url = 'https://homologacao.notainteligente.com' request_path = '/api/action' soap_action = 'RecepcionarLoteRps' post_xml = 'homologacao_recepcionar_lote_rps.xml' ca_certs = ['acrfbv3.cer', 'acserprorfbv3.cer', 'icpbrasilv2.cer'] client_cert = 'solti.cer' client_key = 'solti.key' cert_store = OpenSSL::X509::Store.new.tap do |store| ca_certs.each { |ca_file| store.add_file(ca_file) } end ssl_options = { :ssl => { :verify => false, :client_cert => OpenSSL::X509::Certificate.new(File.read(client_cert)), :client_key => OpenSSL::PKey::RSA.new(File.read(client_key)), :cert_store => cert_store }} xml = File.read(post_xml) request = Faraday::Connection.new request_url, ssl_options request.headers['HTTP_SOAPACTION'] = soap_action request.headers['CONTENT_TYPE'] = 'text/xml;charset="utf-8"' puts "Enviando para: #{request_url}#{request_path}" puts "Action: #{soap_action}" puts xml response = request.post request_path, xml puts response.body