Home > comp > gb.net.curl > httpclient 
  [3.0]
 fr de es it nl pl pt pt_BR mk sq ca ar fa vi ja ru zh zh_TW eo
Previous  Next  Edit  Rename  Undo  Refresh  Search  Administration  
Documentation
History
 
HttpClient (gb.net.curl)
Symbols
This class inherits Curl.
This class is creatable.

Properties  Methods  Events 
Async  ./auth  ByteOrder  ./code  ./cookiesfile  EndOfFile  EndOfLine  Handle  ./headers  Id  Password  Proxy  ./reason  Status  Tag  Timeout  URL  ./updatecookies  User  ./useragent    Close  Get  Peek  ./post  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 synchronously
  '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.Async = FALSE
  h.Timeout = 60
  h.Get

  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