CCurlHttpClient provides a synchronous HTTP client for making GET and POST requests. It wraps libcurl with a simple connect/send/receive/disconnect lifecycle and supports basic authentication, cookies, and SSL certificate verification.
A global singleton instance CurlHttpClient is provided for convenience, but you can also create your own instances.
Header: nel/web/http_client_curl.h
#include <nel/web/http_client_curl.h>
NLWEB::CCurlHttpClient httpClient;
// Connect (initializes CURL)
httpClient.connect("https://example.com");
// Optionally set authentication
httpClient.authenticate("user", "password");
// Optionally disable SSL verification (not recommended for production)
httpClient.verifyServer(false);
// Send a GET request
httpClient.sendGet("https://example.com/api/status");
// Or send a POST request with parameters
httpClient.sendPost("https://example.com/api/login", "user=admin&pass=secret");
// Retrieve the response
std::string response;
httpClient.receive(response);
// Clean up
httpClient.disconnect();
To send a request with a cookie attached:
httpClient.sendGetWithCookie(
"https://example.com/api/data",
"session_id", // cookie name
"abc123", // cookie value
"", // additional params (optional)
false // verbose logging
);
The same pattern is available for POST via sendPostWithCookie.
| Method | Description |
|---|---|
connect(server) |
Initialize CURL and set the server URL. Returns true on success. |
authenticate(user, password) |
Set HTTP basic authentication credentials. |
verifyServer(verify) |
Enable or disable SSL peer and host verification. |
sendGet(url, params, verbose) |
Send a GET request. Parameters are appended as a query string. |
sendGetWithCookie(url, name, value, params, verbose) |
Send a GET request with a cookie. |
sendPost(url, params, verbose) |
Send a POST request with form-encoded parameters. |
sendPostWithCookie(url, name, value, params, verbose) |
Send a POST request with a cookie. |
receive(result, verbose) |
Read the response (headers + body) into a string. |
disconnect() |
Release the CURL handle. |
lastError() |
Return the last CURL error message. |
CURL global initialization and cleanup is reference-counted, so multiple CCurlHttpClient instances can be created and destroyed safely across threads. However, a single CCurlHttpClient instance should not be used concurrently from multiple threads.
The Ryzom client subclasses CCurlHttpClient for login:
class CStartupHttpClient : public NLWEB::CCurlHttpClient
{
bool connectToLogin();
};
The login flow connects to the startup host, sends authentication POST requests, and processes the response to get shard lists and connection cookies. SSL certificate verification can be toggled via the StartupVerify config variable.
For server-side telemetry and audit logging, see HTTP POST Task.