Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HttpRequest

An HTTP request. For most purposes, fetch will be easier to use, but you can use this class when you want to check progress of a request while it is running (using onProgress).

Hierarchy

  • HttpRequest

Index

Properties

onComplete

onComplete: Delegate<(success: boolean) => void>

Called when an HTTP request completes

param

Indicates whether or not the request was able to connect successfully

onProgress

onProgress: Delegate<(sent: number, received: number) => void>

Delegate called per tick to update an HTTP request upload or download size progress

param

The number of bytes uploaded in the request so far

param

The number of bytes downloaded in the response so far

Methods

cancel

  • cancel(): void
  • Cancel a request that is still being processed

    Returns void

getContent

  • getContent(): string
  • Return the payload as a string, assuming the payload is UTF8.

    Returns string

    • The payload as a string.

getContentLength

  • getContentLength(): number
  • Return the size of the payload.

    Returns number

    • The payload size in bytes

getElapsedTime

  • getElapsedTime(): number
  • Return the time that it took for the server to fully respond to the request.

    Returns number

    • Elapsed time in seconds

getMethod

  • getMethod(): string
  • Return the method (GET, PUT, POST, DELETE) used by the request.

    Returns string

    • The method used

getResponseCode

  • getResponseCode(): number
  • Return the HTTP response status code returned by the requested server.

    Returns number

    • The response code

getStatus

  • getStatus(): string
  • Return the current status of the request being processed.

    Returns string

    • The current status. Possible values: NotStarted, Processing, Failed, Succeeded

process

  • process(): void
  • Call to begin processing the request. A request object can be re-used but not while still being processed.

    Returns void

setContent

  • setContent(contentString: string): void
  • Set the content of the request as a string encoded as UTF8.

    Parameters

    • contentString: string

      Payload to set.

    Returns void

setHeader

  • setHeader(headerName: string, headerValue: string): void
  • Set optional header info. Content-Length is the only header automatically set for you. Required headers depend on the request itself, e.g. "multipart/form-data" is needed for a form post.

    Parameters

    • headerName: string

      Name of the header (Content-Type)

    • headerValue: string

      Value of the header

    Returns void

setMethod

  • setMethod(verb: string): void
  • Set the method used by the request. Allowed methods are GET, PUT, POST, and DELETE. Should be set before calling process. If not specified, GET is assumed.

    Parameters

    • verb: string

      Method to use

    Returns void

setURL

  • setURL(url: string): void