HTTPRequestMemory()
Syntax
Result = HTTPRequestMemory(Type, URL$ [, *Data, DataSize [, Flags [, Headers()]]])Description
Send an HTTP request with optional binary data. If text only data needs to be sent HTTPRequest() can be used. This command is designed to handle REST like web API easily. FinishHTTP() needs to be always called once the request has been executed.
Parameters
Type The type of the request. Can be one of the following values: #PB_HTTP_Get : GET request ('*Data' parameter will be ignored) #PB_HTTP_Post : POST request ('*Data' parameter will be sent if specified) #PB_HTTP_Put : PUT request ('*Data' parameter will be sent if specified) #PB_HTTP_Patch : PATCH request ('*Data' parameter will be sent if specified) #PB_HTTP_Delete: DELETE request ('*Data' parameter will be sent if specified)URL$ The URL to send the request to. *Data (optional) The memory buffer to send with the request. DataSize (optional) The size (in bytes) of the memory buffer to send with the request. Flags (optional) It can be a combination of the following values: #PB_HTTP_Asynchronous: starts the download asynchronously. #PB_HTTP_NoRedirect : don't follow automatic redirections. #PB_HTTP_NoSSLCheck : don't check if the SSL certificate is valid (can be useful for testing purpose). #PB_HTTP_HeadersOnly : gets headers only. #PB_HTTP_WeakSSL : to support older servers. #PB_HTTP_Debug : to print in the console debug information.Headers() (optional) A map of string pair to specify additional headers for the request. Example: NewMap Header$() Header$("ContentType") = "octectstream" Header$("User-Agent") = "Firefox 54.0" Header$("NoParamHeader") = "" ; When putting no string value, it will be an empty parameter
Return value
Returns the HTTP request identifier if the call has been successfully initialized, zero otherwise. HTTPInfo() can be used to get some info about the request. If #PB_HTTP_Asynchronous was specified, HTTPProgress() and AbortHTTP() can be used. HTTPMemory() can be used to get the result as a raw buffer (the raw buffer must be freed with FreeMemory()). FinishHTTP() has to be always called to finish a successfully initialized HTTP request, even if the call was synchronous.
Remarks
On Linux, 'libcurl' needs to be installed to have this command working (most of Linux distributions comes with it already installed).
Example
HttpRequest = HTTPRequestMemory(#PB_HTTP_Get, "https://www.google.com") If HttpRequest Debug "StatusCode: " + HTTPInfo(HTTPRequest, #PB_HTTP_StatusCode) Debug "Response: " + HTTPInfo(HTTPRequest, #PB_HTTP_Response) FinishHTTP(HTTPRequest) Else Debug "Request creation failed" EndIf
See Also
HTTPRequest(), URLEncoder(), AbortHTTP()
Supported OS
All