HTTPClient

Low-level hyper-text transfer protocol client.

Hyper-text transfer protocol client (sometimes called "User Agent"). Used to make HTTP requests to download web content, upload files and other data or to communicate with various services, among other use cases. See the HTTPRequest node for a higher-level alternative. Note: This client only needs to connect to a host once (see connectToHost) to send multiple requests. Because of this, methods that take URLs usually take just the part after the host instead of the full URL, as the client is already connected to a host. See request for a full example and to get started. A HTTPClient should be reused between multiple requests or to connect to different hosts instead of creating one client per request. Supports SSL and SSL server certificate verification. HTTP status codes in the 2xx range indicate success, 3xx redirection (i.e. "try again, but over here"), 4xx something was wrong with the request, and 5xx something went wrong on the server's side. For more information on HTTP, see https://developer.mozilla.org/en-US/docs/Web/HTTP (or read RFC 2616 to get it straight from the source: https://tools.ietf.org/html/rfc2616). Note: When performing HTTP requests from a project exported to HTML5, keep in mind the remote server may not allow requests from foreign origins due to url=https://developer.mozilla.org/en-US/docs/Web/HTTP/CORSCORS/url. If you host the server in question, you should modify its backend to allow requests from foreign origins by adding the Access-Control-Allow-Origin: * HTTP header. Note: SSL/TLS support is currently limited to TLS 1.0, TLS 1.1, and TLS 1.2. Attempting to connect to a TLS 1.3-only server will return an error. Warning: SSL/TLS certificate revocation and certificate pinning are currently not supported. Revoked certificates are accepted as long as they are otherwise valid. If this is a concern, you may want to use automatically managed certificates with a short validity period.

@GodotBaseClass
struct HTTPClient {}

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

Constants
enum Constants
Method
enum Method
ResponseCode
enum ResponseCode
Status
enum Status

Functions

close
void close()

Closes the current connection, allowing reuse of this HTTPClient.

connectToHost
GodotError connectToHost(String host, long port, bool use_ssl, bool verify_host)

Connects to a host. This needs to be done before any requests are sent. The host should not have http:// prepended but will strip the protocol identifier if provided. If no port is specified (or -1 is used), it is automatically set to 80 for HTTP and 443 for HTTPS (if use_ssl is enabled). verify_host will check the SSL identity of the host if set to true.

getConnection
Ref!StreamPeer getConnection()
getReadChunkSize
long getReadChunkSize()
getResponseBodyLength
long getResponseBodyLength()

Returns the response's body length. Note: Some Web servers may not send a body length. In this case, the value returned will be -1. If using chunked transfer encoding, the body length will also be -1.

getResponseCode
long getResponseCode()

Returns the response's HTTP status code.

getResponseHeaders
PoolStringArray getResponseHeaders()

Returns the response headers.

getResponseHeadersAsDictionary
Dictionary getResponseHeadersAsDictionary()

Returns all response headers as a Dictionary of structure { "key": "value1; value2" } where the case-sensitivity of the keys and values is kept like the server delivers it. A value is a simple String, this string can have more than one value where "; " is used as separator. Example:

getStatus
HTTPClient.Status getStatus()

Returns a status constant. Need to call poll in order to get status updates.

hasResponse
bool hasResponse()

If true, this HTTPClient has a response available.

isBlockingModeEnabled
bool isBlockingModeEnabled()
isResponseChunked
bool isResponseChunked()

If true, this HTTPClient has a response that is chunked.

opAssign
typeof(null) opAssign(typeof(null) n)
opEquals
bool opEquals(HTTPClient other)
opEquals
bool opEquals(typeof(null) n)
poll
GodotError poll()

This needs to be called in order to have any request processed. Check results with getStatus.

queryStringFromDict
String queryStringFromDict(Dictionary fields)

Generates a GET/POST application/x-www-form-urlencoded style query string from a provided dictionary, e.g.:

readResponseBodyChunk
PoolByteArray readResponseBodyChunk()

Reads one chunk from the response.

request
GodotError request(long method, String url, PoolStringArray headers, String _body)

Sends a request to the connected host. The URL parameter is usually just the part after the host, so for http://somehost.com/index.php, it is /index.php. When sending requests to an HTTP proxy server, it should be an absolute URL. For constant HTTPClient.METHOD_OPTIONS requests, * is also allowed. For constant HTTPClient.METHOD_CONNECT requests, it should be the authority component (host:port). Headers are HTTP request headers. For available HTTP methods, see method. To create a POST request with query strings to push to the server, do:

requestRaw
GodotError requestRaw(long method, String url, PoolStringArray headers, PoolByteArray _body)

Sends a raw request to the connected host. The URL parameter is usually just the part after the host, so for http://somehost.com/index.php, it is /index.php. When sending requests to an HTTP proxy server, it should be an absolute URL. For constant HTTPClient.METHOD_OPTIONS requests, * is also allowed. For constant HTTPClient.METHOD_CONNECT requests, it should be the authority component (host:port). Headers are HTTP request headers. For available HTTP methods, see method. Sends the body data raw, as a byte array and does not encode it in any way.

setBlockingMode
void setBlockingMode(bool enabled)
setConnection
void setConnection(StreamPeer connection)
setReadChunkSize
void setReadChunkSize(long bytes)
toHash
size_t toHash()

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Properties

blockingModeEnabled
bool blockingModeEnabled [@property getter]
bool blockingModeEnabled [@property setter]

If true, execution will block until all data is read from the response.

connection
StreamPeer connection [@property getter]
StreamPeer connection [@property setter]

The connection to use for this client.

readChunkSize
long readChunkSize [@property getter]
long readChunkSize [@property setter]

The size of the buffer used and maximum bytes to read per iteration. See readResponseBodyChunk.

Static functions

_new
HTTPClient _new()

Construct a new instance of HTTPClient. Note: use memnew!HTTPClient instead.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

GDNativeClassBinding
struct GDNativeClassBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(ToRef) as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Meta