ReceiveHTTPMemory()

Syntax

*Buffer = ReceiveHTTPMemory(URL$ [, Flags [, UserAgent$]])
Description
Download a file to a new memory buffer from the given URL$.

Parameters

URL$ The URL to download from.
Flags (optional) It can be a combination of the following value:
  #PB_HTTP_Asynchronous: starts the download asynchronously. To get the memory buffer address use FinishHTTP().
  #PB_HTTP_NoRedirect  : don't follow automatic redirections.
UserAgent$ (optional) Change the user agent for the HTTP request. Default user agent is set to "Mozilla/5.0 Gecko/41.0 Firefox/41.0" for maximum compatibility.

Return value

Returns the new memory buffer address if the download was successful, zero otherwise. MemorySize() can be used to get the size of the downloaded item. The memory buffer needs to be freed with FreeMemory() once finished using it. If #PB_HTTP_Asynchronous was specified, it returns the 'HttpConnection' value needed for HTTPProgress(), AbortHTTP() and FinishHTTP().

Remarks

InitNetwork() has to be called before using this command.

On Linux, 'libcurl' needs to be installed to have this command working (most of Linux distributions comes with it already installed).

Example

  InitNetwork()

  *Buffer = ReceiveHTTPMemory("http://www.purebasic.com/index.php")
  If *Buffer
    Size = MemorySize(*Buffer)
    Debug "Content: " + PeekS(*Buffer, Size, #PB_UTF8|#PB_ByteLength)
    FreeMemory(*Buffer)
  Else
    Debug "Failed"
  EndIf

See Also

GetHTTPHeader(), URLEncoder()

Supported OS

All

<- ReceiveHTTPFile() - Http Index - SetURLPart() ->