WebRequest¶
Inherited: None
Description¶
The WebRequest class provides a mechanism to send HTTP requests (e.g., GET requests) and handle the server’s response. It manages the connection, sends headers, and processes the response, including handling HTTP status codes, headers, and content. This class supports both regular HTTP and HTTPS protocols.
Public Methods¶
const uint8_t |
data () const |
float |
|
int |
downloadedBytes () const |
int |
errorCode () const |
bool |
isDone () |
void |
readAnswer () |
void |
send () |
void |
setHeader (const TString & key, const TString & value) |
text () const |
|
bool |
operator== (const WebRequest & right) const |
Static Methods¶
get (const TString & url) |
Methods Description¶
const uint8_t WebRequest::data () const
Returns the raw response data as a pointer to a uint8_t array.
float WebRequest::downloadProgress ()
Returns the progress of the download as a percentage of the total content size as a float between 0.0f and 1.0f.
int WebRequest::downloadedBytes () const
Returns the number of bytes downloaded so far in the response.
int WebRequest::errorCode () const
Returns the HTTP status code from the server response.
WebRequest * WebRequest::get (TString & url)
Creates a WebRequest object configured for a GET request with the specified url.
bool WebRequest::isDone ()
Checks if the HTTP request has been completed (i.e., response fully received or some error happened). Returns true if the request is complete; otherwise returns false.
void WebRequest::readAnswer ()
Reads the server’s response, handling the status code, headers, and content. This function processes the response in chunks and updates the internal state accordingly.
void WebRequest::send ()
Sends the HTTP request by constructing the appropriate headers, establishing a socket connection, and writing the request to the server.
Adds a custom header to the request. Each field must contain key as a header field name and value.
TString WebRequest::text () const
Returns the content of the response as a String
bool WebRequest::operator== (WebRequest & right) const
Compares WebRequest with right object for equality based on their headers. Returns true if requests are equal; otherwise returns false.