How to submit information to a json api in Delphi 7, Please help me

Asked

Viewed 2,179 times

1

Using Delphi 7 how to send information to an API by clicking a close button?

The data sent would be a JSON.

2 answers

0

Use the Indy library,

Very simple, look at:

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 Website

  • Thank you, I’ll try!

0


Here’s an example of how to send Json to a Webservice

Add the Indy tIDHTTP component to your form and send it to your event from as follows:

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;
  • Lhandler: Tidssliohandlersocketopenssl; I need to use some specific calsse ?

  • Add your Uses Idsslopenssl clause

  • Reginaldo, do you have any other form of contact ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.