Struct gdnative_bindings_lily::HTTPClient [−][src]
pub struct HTTPClient { /* fields omitted */ }
Expand description
core class HTTPClient
inherits Reference
(reference counted).
Official documentation
See the documentation of this class in the Godot engine’s official documentation. The method descriptions are generated from it and typically contain code samples in GDScript, not Rust.
Memory management
The lifetime of this object is automatically managed through reference counting.
Class hierarchy
HTTPClient inherits methods from:
Safety
All types in the Godot API have “interior mutability” in Rust parlance.
To enforce that the official thread-safety guidelines are
followed, the typestate pattern is used in the Ref
and TRef
smart pointers,
and the Instance
API. The typestate Access
in these types tracks whether the
access is unique, shared, or exclusive to the current thread. For more information,
see the type-level documentation on Ref
.
Implementations
Constants
Creates a new instance of this object.
This is a reference-counted type. The returned object is automatically managed
by Ref
.
Closes the current connection, allowing reuse of this HTTPClient.
pub fn connect_to_host(
&self,
host: impl Into<GodotString>,
port: i64,
use_ssl: bool,
verify_host: bool
) -> GodotResult
pub fn connect_to_host(
&self,
host: impl Into<GodotString>,
port: i64,
use_ssl: bool,
verify_host: bool
) -> GodotResult
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
.
Default Arguments
port
--1
use_ssl
-false
verify_host
-true
The connection to use for this client.
The size of the buffer used and maximum bytes to read per iteration. See [method read_response_body_chunk].
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
.
Returns the response’s HTTP status code.
Returns the response headers.
Sample code is GDScript unless otherwise noted.
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:
{
"content-length": 12,
"Content-Type": "application/json; charset=UTF-8",
}
Returns a [enum Status] constant. Need to call [method poll] in order to get status updates.
If true
, this HTTPClient has a response available.
If true
, execution will block until all data is read from the response.
If true
, this HTTPClient has a response that is chunked.
This needs to be called in order to have any request processed. Check results with [method get_status].
Sample code is GDScript unless otherwise noted.
Generates a GET/POST application/x-www-form-urlencoded style query string from a provided dictionary, e.g.:
var fields = {"username": "user", "password": "pass"}
var query_string = http_client.query_string_from_dict(fields)
# Returns "username=user&password=pass"
Furthermore, if a key has a null
value, only the key itself is added, without equal sign and value. If the value is an array, for each value in it a pair with the same key is added.
var fields = {"single": 123, "not_valued": null, "multiple": [22, 33, 44]}
var query_string = http_client.query_string_from_dict(fields)
# Returns "single=123¬_valued&multiple=22&multiple=33&multiple=44"
Reads one chunk from the response.
pub fn request(
&self,
method: i64,
url: impl Into<GodotString>,
headers: StringArray,
body: impl Into<GodotString>
) -> GodotResult
pub fn request(
&self,
method: i64,
url: impl Into<GodotString>,
headers: StringArray,
body: impl Into<GodotString>
) -> GodotResult
Sample code is GDScript unless otherwise noted.
Sends a request to the connected host. The URL parameter is just the part after the host, so for http://somehost.com/index.php
, it is index.php
.
Headers are HTTP request headers. For available HTTP methods, see [enum Method].
To create a POST request with query strings to push to the server, do:
var fields = {"username" : "user", "password" : "pass"}
var query_string = http_client.query_string_from_dict(fields)
var headers = ["Content-Type: application/x-www-form-urlencoded", "Content-Length: " + str(query_string.length())]
var result = http_client.request(http_client.METHOD_POST, "index.php", headers, query_string)
Note: The request_data
parameter is ignored if method
is [constant HTTPClient.METHOD_GET]. This is because GET methods can’t contain request data. As a workaround, you can pass request data as a query string in the URL. See [method String.http_escape] for an example.
Default Arguments
body
-""
pub fn request_raw(
&self,
method: i64,
url: impl Into<GodotString>,
headers: StringArray,
body: ByteArray
) -> GodotResult
pub fn request_raw(
&self,
method: i64,
url: impl Into<GodotString>,
headers: StringArray,
body: ByteArray
) -> GodotResult
Sends a raw request to the connected host. The URL parameter is just the part after the host, so for http://somehost.com/index.php
, it is index.php
.
Headers are HTTP request headers. For available HTTP methods, see [enum Method].
Sends the body data raw, as a byte array and does not encode it in any way.
If true
, execution will block until all data is read from the response.
The connection to use for this client.
The size of the buffer used and maximum bytes to read per iteration. See [method read_response_body_chunk].
Methods from Deref<Target = Reference>
Trait Implementations
type RefKind = RefCounted
type RefKind = RefCounted
Creates an explicitly null reference of Self
as a method argument. This makes type
inference easier for the compiler compared to Option
. Read more
Creates a new instance of Self
using a zero-argument constructor, as a Unique
reference. Read more
Performs a dynamic reference downcast to target type. Read more
Performs a static reference upcast to a supertype that is guaranteed to be valid. Read more
Creates a persistent reference to the same Godot object with shared thread access. Read more
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
Creates a persistent reference to the same Godot object with thread-local thread access. Read more
Creates a persistent reference to the same Godot object with unique access. Read more
Recovers a instance ID previously returned by Object::get_instance_id
if the object is
still alive. See also TRef::try_from_instance_id
. Read more
Auto Trait Implementations
impl RefUnwindSafe for HTTPClient
impl !Send for HTTPClient
impl !Sync for HTTPClient
impl Unpin for HTTPClient
impl UnwindSafe for HTTPClient