Ver Mensaje Individual
  #1523  
Antiguo 21-09-2021
juramisa juramisa is offline
Miembro
 
Registrado: abr 2007
Posts: 54
Reputación: 18
juramisa Va por buen camino
Entorno de pruebas Gipuzkoa

Cita:
Empezado por HerensugeBeltz Ver Mensaje
Hola Juramisa,
Te adjunto el código que uso yo. Los envíos de prueba van bien (es en C++Builder). En mi caso tuve problemas con el método SendFile y tuve que usar PostBytes. XMLOrigen es el fichero XML firmado y grabado en disco.

Código:
..  {
    sbxHTTPClient1->TLSAutoValidateCertificates= true; 
    sbxHTTPClient1->TLSVersions= TsbxConstants::csbTLS12;
    sbxHTTPClient1->ReqParamsContentType= L"application/xml;charset=UTF-8";
    sbxHTTPClient1->ReqParamsAcceptCharset= L"UTF-8";
    sbxHTTPClient1->ReqParamsAccept= L"*/*";
    sbxHTTPClient1->ReqParamsHTTPVersion= TsbxHTTPClientReqParamsHTTPVersions::chvHTTP11;
    sbxHTTPClient1->TLSRenegotiationAttackPreventionMode= TsbxHTTPClientTLSRenegotiationAttackPreventionModes::crapmAuto;
    sbxHTTPClient1->Config(L"UseSystemCertificates=true");
    // Cambio el timeout por defecto
  // SocketDNSTotalTimeout (0): The timeout (in milliseconds) for the whole resolution process
  // SocketTimeout (60000): The maximum period of waiting, in milliseconds, after which the socket operation is considered unsuccessful.
    sbxHTTPClient1->SocketDNSTotalTimeout= 2000;
    sbxHTTPClient1->SocketTimeout= 2500;
..
  }
Muchisimas gracias, ha funcionado a la primera.

Me has salvado.

Os dejo como quedan los envío con SecureBlackBox desde Delphi


Código Delphi [-]
  procedure GuardarRespuesta(const Fichero: string; Respuesta: TBytes);
  var
    stream: TBytesStream;
  begin
    stream := TBytesStream.Create(Respuesta);
    try
      stream.SaveToFile(Fichero);
    finally
      stream.Free;
    end;
  end;
  function bintostr(const bin: array of byte): string;
  const
    HexSymbols = '0123456789ABCDEF';
  var
    i: integer;
  begin
    SetLength(Result, 2 * Length(bin));
    for i := 0 to Length(bin) - 1 do
    begin
      Result[1 + 2 * i + 0] := HexSymbols[1 + bin[i] shr 4];
      Result[1 + 2 * i + 1] := HexSymbols[1 + bin[i] and $0F];
    end;
  end;

procedure p_envio_TicketBai
var 
  la_respuesta : IXMLTicketBaiResponse;

begin
  try
  el_fichero_a_enviar := 'ruta y nombre fichero ticketbai';


if FileExists(el_fichero_a_enviar) then
  WebBrowser1.Navigate(el_fichero_a_enviar);
if FileExists(el_fichero_a_enviar) then
begin

  sbxHTTPClient1.TLSSettings.AutoValidateCertificates := True;
  CertificateStorage := TsbxCertificateStorage.Create(nil);
  if CertificateStorage.Opened then
    CertificateStorage.Close(True);
  CertificateStorage.Open('system://currentuser@localhost/?store=MY');
  encontrado := False;
  sbxHTTPClient1.ClientChain.Clear;
  for i := 0 to CertificateStorage.Certificates.Count - 1 do
  begin
    cert := CertificateStorage.Certificates[i];
    if bintostr(cert.SerialNumber) = mi_certificadoID.Caption then
    begin
      sbxHTTPClient1.ClientChain.Add(cert);
      encontrado := True;
    end;
  end;
  if not encontrado then
  begin
    Application.MessageBox('Firma no encontrada', 'Proceso de firma', MB_OK + MB_ICONWARNING + MB_DEFBUTTON2);
    Exit;
  end;

  sbxHTTPClient1.RequestParameters.ContentType := 'application/xml;charset=UTF-8';
  sbxHTTPClient1.RequestParameters.AcceptCharset := 'UTF-8';
  sbxHTTPClient1.RequestParameters.Accept := '*/*';
  sbxHTTPClient1.RequestParameters.HTTPVersion := TsbxHTTPClientReqParamsHTTPVersions.chvHTTP11;
  sbxHTTPClient1.TLSSettings.RenegotiationAttackPreventionMode := TsbxHTTPClientTLSRenegotiationAttackPreventionModes.crapmAuto;
  sbxHTTPClient1.Config('UseSystemCertificates=true');
  sbxHTTPClient1.SocketSettings.DNSTotalTimeout := 2000;
  sbxHTTPClient1.SocketSettings.Timeout := 2500;
  otros_parametros := 'Accept-Encoding: ' + #13#10
                    + 'Content-Encoding: ' ;
  sbxHTTPClient1.RequestParameters.CustomHeaders := otros_parametros;

  case rg_Entorno.ItemIndex of
    0: sbxHTTPClient1.PostFile(la_url_GI_alta_pruebas, el_fichero_a_enviar);
    1: sbxHTTPClient1.PostFile(la_url_GI_alta, el_fichero_a_enviar);
  end;
  if sbxHTTPClient1.OutputBytes = nil then
    Exit;
  FicheroRespuesta := el_fichero_a_recibir;
  GuardarRespuesta(FicheroRespuesta,sbxHTTPClient1.OutputBytes);

  if FileExists(el_fichero_a_recibir) then
    wbRecepcion.Navigate(el_fichero_a_recibir);
  // Cabecera
  {$REGION Cabecera}
  XMLDocument1 := TXMLDocument.Create(nil);

  XMLDocument1.Active := False;
  XMLDocument1.XML.Clear;
  XMLDocument1.LoadFromFile(el_fichero_a_recibir);

  XMLDocument1.Active := True;

  XMLDocument1.XML.Text := StringReplace(XMLDocument1.XML.Text, 'ns2:TicketBai', 'TicketBai', [rfReplaceAll, rfIgnoreCase]);
  XMLDocument1.XML.Text := StringReplace(XMLDocument1.XML.Text, 'xmlns:ns2', 'xmlns', [rfReplaceAll, rfIgnoreCase]);

  la_respuesta := GetTicketBaiResponse(XMLDocument1);
  .......
Responder Con Cita