How to send information to a json api in Delphi 7, Please help me [closed]

1

Using Delphi 7 to send information to an API when you click a close button?

The data sent would be a JSON.

    
asked by anonymous 23.11.2018 / 18:16

2 answers

0

Following is an example of how to send Json to a WebService

Add the Indy tIDHTTP component to your form and in your event send following form:

var
  Json: string;
  sResponse: string;
  JsonToSend: TStringStream;
  LHandler: TIdSSLIOHandlerSocketOpenSSL;
begin

   LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
   idHTTP.IOHandler := LHandler;

   try

   Json := '{ '+
              ' "email":"[email protected]",'+
              ' "sistema":"meusistema",'+
              ' "cdemp":"codigo"'+
              ' } ';
   JsonToSend := TStringStream.Create(Json, TEncoding.UTF8);
   sResponse := IdHTTP.Post('http://url:porta/api/sistema/esqueciasenha', JsonToSend);


     except
           on e  : Exception  do
           begin
           end;
        end;

      finally
        JsonToSend.Free;
      end;


    end;

   LHandler.Free;

end;
    
23.11.2018 / 18:34
0

Use the library at Indy,

Very simple, see:

var
  HTTP: TIdHTTP;
  vJsonAEnviar: TStringStream;
begin
  HTTP:= TIdHTTP.Create;
  HTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0';

  HTTP.Get('endereco\api\dados={json}');    
  //ou
  vJsonAEnviar := TStringStream.Create(UTF8Encode('{json}'));
  HTTP.Post('endereco', vJsonAEnviar);
  FreeAndNil(HTTP);
  FreeAndNil(vJsonAEnviar);
end;

Source: Indy Project Official Site

    
23.11.2018 / 18:32