Home / comp / gb.net.curl / httpclient 
HttpClient (gb.net.curl)
Symbols
This class inherits Curl.
This class is creatable.

Properties  Methods  Events 
/comp/gb.net.curl/curl/async  /comp/gb.net.curl/httpclient/auth  ByteOrder  /comp/gb.net.curl/httpclient/code  /comp/gb.net.curl/httpclient/cookiesfile  EndOfFile  EndOfLine  Handle  /comp/gb.net.curl/httpclient/headers  Id  /comp/gb.net.curl/curl/password  /comp/gb.net.curl/curl/proxy  /comp/gb.net.curl/httpclient/reason  /comp/gb.net.curl/curl/status  /comp/gb.net.curl/curl/tag  /comp/gb.net.curl/curl/timeout  /comp/gb.net.curl/curl/url  /comp/gb.net.curl/httpclient/updatecookies  /comp/gb.net.curl/curl/user  /comp/gb.net.curl/httpclient/useragent    Close  /comp/gb.net.curl/httpclient/get  /comp/gb.net.curl/curl/peek  /comp/gb.net.curl/httpclient/post  /comp/gb.net.curl/httpclient/stop    /comp/gb.net.curl/curl/.connect  /comp/gb.net.curl/curl/.error  /comp/gb.net.curl/curl/.finished  /comp/gb.net.curl/curl/.read   

Examples

PUBLIC SUB getfile()
  'How to download a file from the internet
  'The following code works in Gambas version 1.0.15
  'On 2007-jun-17, Daniel Compos noted that for Gambas v 1.9.49+:
  '   Put the "Async" PROPERTY set TO FALSE prior TO Get(), that way
  '   Get() will STOP the program flow UNTIL all the information IS
  '   received. In that CASE you should USE also the "TimeOut" PROPERTY TO
  '   set a timeout, IF NOT, it could hang forvever IF the server does NOT
  '   reply properly.

  DIM h AS HttpClient
  DIM buffer AS String
  h = NEW HttpClient AS "h"
  h.URL = "http://elinks.or.cz/"
  h.Get

  DO WHILE h.Status<>0
    WAIT 0.01
  LOOP

  PRINT "begin"
  IF h.Status<0 THEN
    PRINT "ERROR"
  ELSE
    ' Success - read the data
    IF Lof(h) THEN READ #h, buffer, Lof(h)
    PRINT buffer
  END IF

  PRINT "end"

END

This example shows how you can download a file from the internet asynchronously. Call the DownloadAsync method with your url. Then when the download is complete display the HTML in the Finished event.

PUBLIC _downloadAsync AS NEW HttpClient AS "_Download"
PRIVATE downloadBuffer AS String

PUBLIC SUB DownloadAsync(URL as String)
  downloadBuffer = ""
  _downloadAsync.URL = URL
  _downloadAsync.TimeOut = 20
  _downloadAsync.Get()
END

PUBLIC SUB _Download_Connect()
  PRINT "Connection found " & _downloadAsync.URL
END

PUBLIC SUB _Download_Read()
  DIM buffer AS String
  READ #LAST, buffer, Lof(LAST)
  downloadBuffer &= buffer
END

PUBLIC SUB _Download_Error()
  PRINT "Error " & _downloadAsync.Status & " downloading " & _downloadAsync.URL
END

PUBLIC SUB _Download_Finished()
  PRINT downloadBuffer
END