Hola yo lo hice con 2 componentes de las ICS
TSslHttpCli y TSslContext;
// Consulta a Padrón Nivel 3 WSPN3
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OverbyteIcsWSocket, OverbyteIcsWndControl, OverbyteIcsHttpProt,
StdCtrls, Buttons;
type
TForm1 = class(TForm)
SslHttpCli1: TSslHttpCli;
SslContext1: TSslContext;
Label5: TLabel;
ConsultarCuitBB: TBitBtn;
ICSMemo1M: TMemo;
Memo1: TMemo;
SalirBB: TBitBtn;
ConsultarCuitE: TEdit;
procedure SslHttpCli1RequestDone(Sender: TObject; RqType: THttpRequest;
ErrCode: Word);
procedure ConsultarCuitBBClick(Sender: TObject);
procedure SalirBBClick(Sender: TObject);
private
sAux : string;
function BuscoValorDelNodo1(const sTexto:String; const sNodoABuscar:string; var sRespuesta:string):boolean;
public
end;
var
Form1: TForm1;
implementation
uses StrUtils;
const
myEOL = #13+#10;
{$R *.dfm}
procedure TForm1.ConsultarCuitBBClick(Sender: TObject);
var
nCantErrores :byte;
sCuit : string;
sRespu :string;
const nMAX_ERRORES = 2;
begin
ConsultarCuitBB.Enabled := False;
ConsultarCuitBB.Update;
ConsultarCuitE.Text := StringReplace(ConsultarcuitE.Text,'-','',[rfReplaceAll]);
sCuit := ConsultarCuitE.Text;
SslHttpCli1.URL := 'https://soa.afip.gob.ar/sr-padron/v2/persona/'+
sCuit;
SslHttpCli1.RcvdStream := TMemoryStream.Create;
nCantErrores :=0;
while True do begin
try
IcSMemo1M.Lines.Clear;
SslHttpCli1.Get;
except
on E: Exception do begin
if e.Message = 'Connection aborted on request' then begin
ICSMemo1M.Lines.Append('Error al conectar, verifique tener libeay32.dll y ssleay32.dll'+myeol+
e.Message );
ConsultarCuitBB.Enabled := True;
Exit;
end;
ICSMemo1M.Lines.Append(myEOL+'Error al conectar '+myeol+e.Message );
ConsultarCuitBB.Enabled := True;
exit;
end;
end;
if SslHttpCli1.RcvdCount = 0 then begin
Inc(nCantErrores);
sAux := DateTimeToStr(Now) + ' ERROR DE CONEXION, RX, ' +
' INTENTO ' + IntToStr(nCantErrores) +myeol+ 'VERIFIQUE QUE EXISTE LIBEAY32.DLL Y SSLEAY32.DLL' ;
ICSMemo1M.Lines.Append(sAux);
if nCantErrores <= nMAX_ERRORES then begin
ICSMemo1M.Lines.Append('Intento '+intToStr(nCantErrores));
end else
begin
ICSMemo1M.Lines.Append(sAux);
Break;
end;
Continue;
end;
Break;
end;
SslHttpCli1.RcvdStream.Free;
SslHttpCli1.RcvdStream := nil;
if BuscoValorDelNodo1(ICSMemo1M.Text,'success', sRespu) = True then begin
Memo1.Lines.Append('success='+sRespu);
end else begin
memo1.Lines.Append('No se encuentra cuit ' + sCuit + myeol+
ICSMemo1m.Text);
end;
if BuscoValorDelNodo1(ICSMemo1M.Text,'idPersona', sRespu) = True then begin
Memo1.Lines.Append('idPersona='+sRespu);
end else begin
memo1.Lines.Append('No se encuentra cuit ' + sCuit + myeol+
ICSMemo1m.Text);
end;
if BuscoValorDelNodo1(ICSMemo1M.Text,'tipoPersona', sRespu) = True then begin
Memo1.Lines.Append('tipoPersona='+ sRespu);
end else begin
memo1.Lines.Append('No se encuentra tipoPersona para ' + sCuit + myeol+
ICSMemo1m.Text);
end;
ConsultarCuitBB.Enabled := True;
end;
function TForm1.BuscoValorDelNodo1(const sTexto:String; const sNodoABuscar:string; var sRespuesta:string):boolean;
var n,n2,nLongNodo:integer;
begin
n:=Pos('"' + sNodoABuscar + '":',sTexto);
if n = 0 then begin Result := False;
sRespuesta := '';
Exit;
end;
Result := True;
nLongNodo := Length(sNodoABuscar) + 3;
if sTexto[n + nLongNodo ] = '[' then begin n2 := PosEx(']',sTexto,n) +1 ;
end
else
n2 := PosEx(',',sTexto,n);
if sTexto[n2-1] = '}' then Dec(n2);
sRespuesta := copy(sTexto,n+nLongNodo,n2-n-nLongNodo);
end;
procedure TForm1.SslHttpCli1RequestDone(Sender: TObject;
RqType: THttpRequest; ErrCode: Word);
var
Data : String;
begin
SslHttpCli1.SendStream.Free;
SslHttpCli1.SendStream := nil;
if ErrCode <> 0 then begin
ICSMemo1M.Lines.Append('Post error #' + IntToStr(ErrCode));
SslHttpCli1.RcvdStream.Free;
SslHttpCli1.RcvdStream := nil;
Exit;
end;
if SslHttpCli1.StatusCode <> 200 then begin
ICSMemo1M.Lines.Append('Post error: ' + IntToStr(SslHttpCli1.StatusCode) +
SslHttpCli1.ReasonPhrase);
SslHttpCli1.RcvdStream.Free;
SslHttpCli1.RcvdStream := nil;
Exit;
end;
SslHttpCli1.RcvdStream.Seek(0, 0);
SetLength(Data, SslHttpCli1.RcvdStream.Size);
SslHttpCli1.RcvdStream.Read(Data[1], Length(Data));
ICSMemo1M.Lines.Append(Data);
end;
procedure TForm1.SalirBBClick(Sender: TObject);
begin
Close;
end;
end.