Documentation

Net::HttpRequest

Class

Holds the state of an executing HTTP request.

Properties

Headers for the request. Note that if the User-Agent header is not present, one will automatically be added with basic information about your plugin. It is therefore not recommended to pass in a custom User-Agent header.

Whether or not to follow redirects.

Behaviors

Net::HttpRequest@ HttpRequest()

Creates a new GET request.

Net::HttpRequest@ HttpRequest(const string&in url)

Creates a new GET request with the given URL.

Net::HttpRequest@ HttpRequest(const string&in url, const string&in body)

Creates a new POST request with the given URL and body.

Methods

awaitable@ Start()

Starts executing the request. Does nothing if the request has already started.

Returns awaitable@
awaitable@ StartToFile(const string&in path)

Starts executing the request, writing the response to the given path. Throws an exception if the request has already started.

Returns awaitable@
bool Finished()

Returns true if the request has finished execution. This will return true even in the case of an error.

Returns bool
int64 ProgressDownload()

Returns the number of bytes that has been downloaded from the server.

Returns int64
int64 ProgressDownloadTotal()

Returns the total number of bytes that are expected to be returned from the server. Note that this can be 0 before the server has sent its Content-Length header, or if it never sends the header at all.

Returns int64
int64 ProgressUpload()

Returns the number of bytes that has been uploaded to the server.

Returns int64
int64 ProgressUploadTotal()

Returns the total number of bytes that are expected to be uploaded to the server.

Returns int64
void Cancel()

Cancels the request. Throws an exception when the request is not yet started.

string Error()

Returns an error message, if there was an error. Otherwise, this returns an empty string. This function is useful in the rare case that ResponseCode() returns 0.

Returns string
int ResponseCode()

Returns the HTTP response code, for example 200 or 404.

Returns int
string ResponseHeader(const string&in key)

Gets the value of a specific response header. The key is case insensitive.

Returns string
dictionary@ ResponseHeaders()

Gets a dictionary of all response headers.

Returns dictionary@
string String()

Returns the response body as a string.

Returns string
Json::Value@ Json()

Returns the response body as a Json value.

Returns Json::Value@
MemoryBuffer@ Buffer()

Returns the response body as a MemoryBuffer.

Returns MemoryBuffer@
void SaveToFile(const string&in path)

Saves the response body to a file. The given path should be an absolute path.