HttpClient (gb.net.curl)

This class provides an HTTP client that sends requests to an HTTP server, and receives the response.

This class inherits Curl.
This class is
Creates a new HTTP client.
creatable
.

Static properties

Static methods
Return or set default proxy of all newly created HttpClient objects.
DefaultProxy  
Download  

Properties

Methods Events
Returns or sets whether the FTP/HTTP request will be asynchronous.
Async  
Return or set the HTTP authentication mode to use.
Auth  
Returns or sets if the stream is blocking.
Blocking  
Return or set the preferred receive buffer size, between 0 and 512 KB.
BufferSize  
Returns or sets the byte order used to read or write binary data to the stream.
ByteOrder  
Returns the HTTP Status Code sent by the server.
Code  
Return or set the file that will be used for reading and storing cookies.
CookiesFile  
Return or set the debugging mode.
Debug  
Return the number of bytes that have been downloaded.
Downloaded  
Return or set the "Accept-Encoding" HTTP header.
Encoding  
This property signals whether the last use of LINE INPUT reached the end of file, instead of reading a full line with an end-of-line character.
EndOfFile  
Returns or sets the newline separator used by this stream.
EndOfLine  
Return if a stream reached its end.
Eof  
Return the error string associated with the error code returned by the curl library.
ErrorText  
Returns the system file descriptor associated with this Stream.
Handle  
Return the HTTP headers as a String array.
Headers  
Return if a stream is associated with a terminal.
IsTerm  
Returns a virtual object that allows you to enumerate a stream line by line.
Lines  
NullTerminatedString  
Returns or sets the password used for authorization.
Password  
Returns a virtual object used for defining proxy parameters.
Proxy  
Return the HTTP reason string.
Reason  
Return or set if the HttpClient must follow HTTP redirections.
Redirect  
This virtual property allows to define the SSL properties of the CURL connection.
SSL  
Returns the status of the client.
Status  
Returns or sets the tag associated with the stream.
Tag  
Return or set the target file used for download operations.
TargetFile  
Return a virtual object that allows to manage the terminal associated with the stream.
Term  
Returns or sets the client timeout in seconds.
Timeout  
Returns the total number of bytes that are expected to be downloaded.
TotalDownloaded  
Returns the total number of bytes that are expected to be uploaded.
TotalUploaded  
Return or set the URL of the resource to download.
URL  
Return or set if cookies must be updated. The default value is False.
UpdateCookies  
Return the number of bytes that have been uploaded.
Uploaded  
Returns or sets the user used for authorisation.
User  
Returns or sets the UserAgent used to make the request.
UserAgent  
Start to buffer data written to the stream, so that everything will be sent when the Send method is called.
Begin  
Closes the stream.
Close  
Fill the HttpClient object from the properties of another HttpClient object.
CopyFrom  
Drop the data that has been buffered since the last call to the Begin method.
Drop  
This method performs a call to the http server using the standard 'GET' method.
Get  
This method performs a call to the http server using the standard 'HEAD' method.
Head  
Returns the contents of the internal stream buffer.
Peek  
This method performs a call to the http server using the standard 'POST' method.
Post  
Send a file through a POST request.
PostFile  
Send some data to a specific URL by using the "PUT" method.
Put  
Send a file through a PUT request.
PutFile  
Read a line of text from the stream, like the LINE INPUT instruction.
ReadLine  
Send all the data, in one shot, since the last call to Begin.
Send  
Aborts the request.
Stop  
Start or stop watching the stream file descriptor for reading or writing, after it has been opened.
Watch  
This event is raised when a request has been cancelled.
Cancel  
Raised when the connection is established.
Connect  
Raised when there was an error returned by the CURL library.
Error  
Raised when a command terminates correctly.
Finished  
This event is raised periodically when something is downloaded or uploaded.
Progress  
Raised when there is some data received.
Read  

Example

' How to download a file from the internet synchronously

' 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 forever if the server does not
' reply properly.

Public Sub GetFile()

  Dim hClient As HttpClient
  Dim sBuffer As String

  hClient = New HttpClient As "hClient"
  hClient.URL = "http://elinks.or.cz/"
  hClient.Async = False
  hClient.Timeout = 60
  hClient.Get

  Print "Begin"
  If hClient.Status < 0 Then
    Print "ERROR"
  Else
    ' Success - read the data
    If Lof(hClient) Then sBuffer = Read #hClient, Lof(hClient)
    Print sBuffer
  End If

  Print "end"

End

Example #2

This second example shows how you can download a file from the internet asynchronously.

It calls the DownloadAsync method with your URL. Then, when the download is completed, it displays the received HTML in the Finished event handler.

' How to download a file from the internet asynchronously

Public hAsyncClient As New HttpClient As "hAsyncClient"
Private sDownloadBuffer As String

Public Sub DownloadAsync(URL As String)

  sDownloadBuffer = ""
  hAsyncClient.URL = URL
  hAsyncClient.TimeOut = 20
  hAsyncClient.Async = True
  hAsyncClient.Get()

End

Public Sub hAsyncClient_Connect()

  Print "Connected to " & hAsyncClient.URL

End

Public Sub hAsyncClient_Read()

  Dim sBuffer As String

  sBuffer = Read #Last, Lof(Last)
  sDownloadBuffer &= sBuffer

End

Public Sub hAsyncClient_Error()

  Print "Error " & hAsyncClient.Status & " while downloading " & hAsyncClient.URL

End

Public Sub hAsyncClient_Finished()

  Print sDownloadBuffer

End