Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Colaboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 27-03-2026
andressanchez andressanchez is offline
Miembro
 
Registrado: jul 2005
Ubicación: Sando Domingo, Rep. Dom.
Posts: 119
Poder: 22
andressanchez Va por buen camino
Hola!

Ya pude instalar Indy 10 y todo marcha bien.

Comparto implementación HTTPS GET.

Código Delphi [-]
unit Unit1;

interface
uses IdHTTP, uLkJSON, SysUtils, Dialogs, IdCTypes,
  IdSSLOpenSSLHeaders, IdBaseComponent, IdComponent, IdIOHandler,
  IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL;

function ObtenerDatosJSON(const URL: string): TlkJSONobject;

implementation

function ObtenerDatosJSON(const URL: string): TlkJSONobject;
var
  Http: TIdHTTP;
  LHandler: TIdSSLIOHandlerSocketOpenSSL;
  Respuesta: string;
begin
  Result := nil;
  Http := TIdHTTP.Create(nil);
  try
    LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    try
      Http.IOHandler := LHandler;
      LHandler.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
      
      // Realizar el HTTP GET
      Respuesta := Http.Get(URL);
      
      // Parsear la respuesta a objeto JSON
      Result := TlkJSON.ParseText(Respuesta) as TlkJSONobject;
    except
      on E: Exception do
        ShowMessage('Error: ' + E.Message);
    end;
  finally
    Http.Free;
    LHandler.Free;
  end;
end;

end.

Aqui su consumo. En Form1 debe ser agregada la libreria uLkJSON y Unit1

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  JsonObj: TlkJSONobject;
  ValorNombre: string;
begin
  JsonObj := ObtenerDatosJSON(FPrincipal.URLPolaris +
  'autenticacion/token?authtoken=' + FPrincipal.AccesTokenPolaris);
  if Assigned(JsonObj) then
  begin
    try
      // Acceder a un campo (ejemplo: {"data": "xyz"})
      ValorNombre := JsonObj.getString('data');
      ShowMessage(ValorNombre);
    finally
      JsonObj.Free; // ¡Importante liberar memoria!
    end;
  end;

end;


El próximo ejercicio que haré será realizar una petición HTTPS POST.

Saludos.-
Responder Con Cita
  #2  
Antiguo 28-03-2026
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.711
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Responder Con Cita
  #3  
Antiguo 30-03-2026
andressanchez andressanchez is offline
Miembro
 
Registrado: jul 2005
Ubicación: Sando Domingo, Rep. Dom.
Posts: 119
Poder: 22
andressanchez Va por buen camino
¡Hola!

Todo funciona correctamente con la implementacion de HTTPS POST.

Código Delphi [-]
procedure EnviarECF(FacturaJSON:string);
var
  IdHTTP: TIdHTTP;
  RequestBody: TStringStream;
  ResponseBody: string;
  JsonString: string;
  URL: string;
  // If using HTTPS, an IOHandler is needed
  LHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
  URL := 'https://example.com/api/endpoint';
  IdHTTP := TIdHTTP.Create(nil);
  RequestBody := TStringStream.Create('');

  try
      // *** If the URL is HTTPS, create and assign the SSL IOHandler ***
      try
        LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
        LHandler.SSLOptions.Method := sslvTLSv1_2;
        LHandler.SSLOptions.SSLVersions := [sslvTLSv1_2];
        IdHTTP.IOHandler := LHandler;
        // Configure SSL options if necessary (TLS version, etc.)

        JsonString := FacturaJSON; // Your JSON data

        IdHTTP.Request.Accept := 'application/json';
        IdHTTP.Request.ContentType := 'application/json'; // Set content type

        // Write JSON string to the stream
        RequestBody.WriteString(JsonString);
        RequestBody.Position := 0; // Reset stream position to the beginning

        // Perform the POST request
        ResponseBody := IdHTTP.Post(URL, RequestBody);

        // Process the response 
        ShowMessage('Response: ' + ResponseBody);

    except
      on E: EIdHTTPProtocolException do
        ShowMessage('HTTP Error: ' + E.Message + ' ' + E.ErrorMessage);
      on E: Exception do
        ShowMessage('Error: ' + E.Message);
    end;
  finally
    // Free objects
    FreeAndNil(RequestBody);
    FreeAndNil(IdHTTP);
    // IOHandler is freed with IdHTTP if it is the owner
  end;

end;

Así consumimos el procedure anterior desde un formulario. Memo1 contiene el JSON.

Código Delphi [-]

procedure TFeCFEnvio.btEnviarClick(Sender: TObject);
begin

EnviarECF(Memo1.Lines.Text);

end;

Seguimos evaluando proveedores.

Nuevamente muchas gracias!
Saludos.-
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
enviar objeto con delphi xe8 a restful con php jgutti PHP 0 10-07-2017 18:29:31


La franja horaria es GMT +2. Ahora son las 02:26:16.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi