In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Working TInternet post example

Xailer English public forum
ftwein
Posts: 34
Joined: Mon Oct 22, 2007 5:17 pm

Working TInternet post example

Postby ftwein » Fri May 24, 2019 4:35 pm

Tested with https://jsonplaceholder.typicode.com/

Code: Select all

METHOD Button2Click( oSender ) CLASS TForm1
LOCAL cTexto, cData, xerro, cJson
LOCAL oInternet, Connection, File
::oMemo1:Value:= ""
BEGIN SEQUENCE
   oInternet:= TInternet():New( Self )
   oInternet:nPort := INTERNET_DEFAULT_HTTPS_PORT
   oInternet:cAgent := "Panel2"
   oInternet:nTimeOut:= 60000
   IF !oInternet:Open()
      BREAK "Not Open"
   ENDIF
   Connection:= oInternet:Connect("jsonplaceholder.typicode.com")
   IF !Connection
      BREAK "Not Connection"
   ENDIF
   cJson:= '{ "title": "foo", "body": "bar", "userId": 1 }'
   File:= oInternet:OpenRequest(;
    "POST",;
    "/posts",;
    INTERNET_FLAG_SECURE,;
    "HTTP/1.0")
   IF !oInternet:SendRequest(;
      File,;
      "Content-type: application/json",;
      cJson )
      BREAK "Not SendRequest"
   ENDIF
   cTexto:=''
   WHILE oInternet:ReadFile( File, @cData, 65536 )
       cTexto += cData
   ENDDO
   ::oMemo1:Value:= cTexto + " *** "+oInternet:GetErrorDescription()

RECOVER USING xerro
   ::oMemo1:Value:= oInternet:GetErrorDescription()
   MsgInfo( xerro )
END SEQUENCE


Regards,

Fausto Di Creddo Trautwein

Return to “English”