HTTPRequest()

Syntax

HTTPRequest(Type, URL$, Parameters, Callback [, UserData [, Headers()]])
Description
Download a file to disk from the given URL$.

Parameters

Type The type of the request. Can be one of the following value:
  #PB_HTTP_Get:  executes a "GET" type request. The result will be returned in the callback 
                 once the request has been fully executed.
  #PB_HTTP_Post: executes a "POST" type request. The result will be returned in the callback 
                 once the request has been fully executed.
  #PB_HTTP_Put: executes a "PUT" type request. The result will be returned in the callback 
                 once the request has been fully executed.
  #PB_HTTP_Patch: executes a "PATCH" type request. The result will be returned in the callback 
                 once the request has been fully executed.
  #PB_HTTP_Delete: executes a "DELETE" type request. The result will be returned in the callback 
                 once the request has been fully executed.
URL$ The URL to execute the request. Due to security constraints, it is only possible to execute a request on the same domain.
Parameters The parameter list.
Callback The callback to be called once the request has been executed. It has to use the following syntax:
  Procedure Callback(Success, Result$, UserData)
    ; Success : #True if the request has been correctly executed, #False otherwise
    ; Result$ : The result of the request, as a text object
    ; UserData: The value specified in UserData parameter of HTTPRequest() or zero if not specified.
  EndProcedure
UserData (optional) A custom user value which will be passed to the callback in the "UserData" parameter.
Headers() (optional) A string map of custom headers to set when sending the request.

Return value

None.

Example

  Procedure HttpGetEvent(Success, Result$, UserData)
    If Success
      Debug Result$
    Else
      Debug "HTTPRequest(): Error"
    EndIf
  EndProcedure
  
  ; Get the content of this file, and display it in the debug window
  ;
  HTTPRequest(#PB_HTTP_Get, #PB_Compiler_Filename, "", @HttpGetEvent())

Example: With custom headers

  Procedure HttpGetEvent(Success, Result$, UserData)
    If Success
      Debug Result$
    Else
      Debug "HTTPRequest(): Error"
    EndIf
  EndProcedure

  NewMap Headers$()
  Headers$("x-customheader") = "test"
  Headers$("x-customvalue") = "10"
  
  HTTPRequest(#PB_HTTP_Get, #PB_Compiler_Filename, "", @HttpGetEvent(), 0, Headers$())

See Also

URLEncoder()

Supported OS

All

Http Index - URLDecoder() ->