Home > comp > gb.net.curl > httpclient 
  [3.0]
 fr de es it nl pl pt pt_BR mk sq ca hu tr ar fa vi ko 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.
Properties  Methods  Events 
Async  ByteOrder  EndOfFile  EndOfLine  Handle  Id  Password  Proxy  Status  Tag  Timeout  URL  User    Close  Peek    /comp/gb.net.curl/curl/.connect  /comp/gb.net.curl/curl/.error  /comp/gb.net.curl/curl/.finished  /comp/gb.net.curl/curl/.read   

This class is creatable.

Properties  Methods 
./auth  ./code  ./cookiesfile  ./headers  ./reason  ./updatecookies  ./useragent    Get  ./post  Stop   

Example

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