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 24-03-2026
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is online now
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 19.439
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Cita:
Empezado por duilioisola Ver Mensaje
Para tratar JSON una buena opción es la librería uLkJSON.
Yo también he usado en varias ocasiones la libería ulkJSON. Funciona muy bien con Delphi 7.
Hay varias entradas en el blog donde puedes ver cómo se usa.

En concreto esta:
https://neftali.clubdelphi.com/habla...weathermap-12/

Puedes ver cómo conectarte a un WebService utilizando Indy y cómo "parsear" los resultados utilizando la librería ulkJSON.
El código está disponible y puedes echarle un vistazo.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #2  
Antiguo 25-03-2026
andressanchez andressanchez is offline
Miembro
 
Registrado: jul 2005
Ubicación: Sando Domingo, Rep. Dom.
Posts: 119
Poder: 21
andressanchez Va por buen camino
Gracias Neftali!

Estuve explorando el código del proyecto que indicas en Delphi 7.

Voy a probar con Indy 9 y la libería ulkJSON. Empezaré realizando peticiones HTTP GET y creando contenido en formato JSON.

Les dejaré saber cómo me fue.

Saludos.-
Responder Con Cita
  #3  
Antiguo 26-03-2026
andressanchez andressanchez is offline
Miembro
 
Registrado: jul 2005
Ubicación: Sando Domingo, Rep. Dom.
Posts: 119
Poder: 21
andressanchez Va por buen camino
Hice la petición HTTP GET y lanzó la excepción:

Cita:
IOHandler value is not valid
Investigando encontré que está relacionado a que debo de actualizar a Indy 10 y los demás componentes que bien indicó duilioisola.
Responder Con Cita
  #4  
Antiguo 26-03-2026
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.670
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Tienes que usar Indy 10.
Responder Con Cita
  #5  
Antiguo 27-03-2026
andressanchez andressanchez is offline
Miembro
 
Registrado: jul 2005
Ubicación: Sando Domingo, Rep. Dom.
Posts: 119
Poder: 21
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
  #6  
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.670
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Responder Con Cita
  #7  
Antiguo 30-03-2026
andressanchez andressanchez is offline
Miembro
 
Registrado: jul 2005
Ubicación: Sando Domingo, Rep. Dom.
Posts: 119
Poder: 21
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 07:05:39.


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