Provides HTTP request functionality using libcurl.
More...
#include <NHttpRequest.h>
|
|
| NHttpRequest () |
| | Constructs a new NHttpRequest instance.
|
| |
|
virtual | ~NHttpRequest () |
| | Destroys the NHttpRequest instance.
|
| |
| std::string | get (const std::string &url, const std::string &cert_path="", const std::string &key_path="", const std::string &key_password_file="", bool insecure=false) |
| | Performs an HTTP GET request. More...
|
| |
| std::string | post (const std::string &url, const std::string &post_data, const std::string &cert_path="", const std::string &key_path="", const std::string &key_password_file="", bool insecure=false) |
| | Performs an HTTP POST request. More...
|
| |
| int | head (const std::string &url, const std::string &cert_path="", const std::string &key_path="", const std::string &key_password_file="", bool insecure=false) |
| | Performs an HTTP HEAD request. More...
|
| |
|
| CURLcode | request (const std::string &method, const std::string &url, const std::string &data, std::ostringstream &response, const std::string &cert_path, const std::string &key_path, const std::string &key_password_file, bool insecure) |
| | Internal method to perform an HTTP request. More...
|
| |
| void | throw_curl_error (CURLcode res) const |
| | Throws an exception if a CURL error occurs. More...
|
| |
|
| static size_t | WriteCallback (void *contents, size_t size, size_t nmemb, void *userp) |
| | Callback for writing response data. More...
|
| |
| static size_t | HeaderCallback (char *buffer, size_t size, size_t nitems, void *userdata) |
| | Callback for handling response headers. More...
|
| |
|
|
CURL * | curl |
| | libcurl handle
|
| |
|
struct curl_slist * | headers |
| | List of custom headers.
|
| |
|
std::vector< std::string > | received_headers |
| | Received response headers.
|
| |
Provides HTTP request functionality using libcurl.
NHttpRequest wraps libcurl to perform HTTP GET, POST, and HEAD requests, supporting client certificate authentication and custom error handling. It offers methods for sending requests and retrieving responses, and handles headers and SSL options.
- Author
- Martin Vala mvala.nosp@m.@cer.nosp@m.n.ch
Definition at line 21 of file NHttpRequest.h.
◆ get()
| std::string Ndmspc::NHttpRequest::get |
( |
const std::string & |
url, |
|
|
const std::string & |
cert_path = "", |
|
|
const std::string & |
key_path = "", |
|
|
const std::string & |
key_password_file = "", |
|
|
bool |
insecure = false |
|
) |
| |
Performs an HTTP GET request.
- Parameters
-
| url | The target URL. |
| cert_path | Path to client certificate (optional). |
| key_path | Path to private key (optional). |
| key_password_file | Path to key password file (optional). |
| insecure | If true, disables SSL verification. |
- Returns
- Response body as a string.
Definition at line 32 of file NHttpRequest.cxx.
Referenced by Ndmspc::NUtils::OpenMacro().
◆ head()
| int Ndmspc::NHttpRequest::head |
( |
const std::string & |
url, |
|
|
const std::string & |
cert_path = "", |
|
|
const std::string & |
key_path = "", |
|
|
const std::string & |
key_password_file = "", |
|
|
bool |
insecure = false |
|
) |
| |
Performs an HTTP HEAD request.
- Parameters
-
| url | The target URL. |
| cert_path | Path to client certificate (optional). |
| key_path | Path to private key (optional). |
| key_password_file | Path to key password file (optional). |
| insecure | If true, disables SSL verification. |
- Returns
- HTTP status code.
Definition at line 56 of file NHttpRequest.cxx.
Referenced by Ndmspc::NUtils::AccessPathName().
◆ HeaderCallback()
| size_t Ndmspc::NHttpRequest::HeaderCallback |
( |
char * |
buffer, |
|
|
size_t |
size, |
|
|
size_t |
nitems, |
|
|
void * |
userdata |
|
) |
| |
|
staticprivate |
Callback for handling response headers.
- Parameters
-
| buffer | Pointer to header data. |
| size | Size of a data unit. |
| nitems | Number of data units. |
| userdata | User pointer (header storage). |
- Returns
- Number of bytes handled.
Definition at line 186 of file NHttpRequest.cxx.
◆ post()
| std::string Ndmspc::NHttpRequest::post |
( |
const std::string & |
url, |
|
|
const std::string & |
post_data, |
|
|
const std::string & |
cert_path = "", |
|
|
const std::string & |
key_path = "", |
|
|
const std::string & |
key_password_file = "", |
|
|
bool |
insecure = false |
|
) |
| |
Performs an HTTP POST request.
- Parameters
-
| url | The target URL. |
| post_data | Data to post. |
| cert_path | Path to client certificate (optional). |
| key_path | Path to private key (optional). |
| key_password_file | Path to key password file (optional). |
| insecure | If true, disables SSL verification. |
- Returns
- Response body as a string.
Definition at line 44 of file NHttpRequest.cxx.
◆ request()
| CURLcode Ndmspc::NHttpRequest::request |
( |
const std::string & |
method, |
|
|
const std::string & |
url, |
|
|
const std::string & |
data, |
|
|
std::ostringstream & |
response, |
|
|
const std::string & |
cert_path, |
|
|
const std::string & |
key_path, |
|
|
const std::string & |
key_password_file, |
|
|
bool |
insecure |
|
) |
| |
|
private |
Internal method to perform an HTTP request.
- Parameters
-
| method | HTTP method ("GET", "POST", "HEAD"). |
| url | The target URL. |
| data | Data to send (for POST). |
| response | Output stream for response data. |
| cert_path | Path to client certificate. |
| key_path | Path to private key. |
| key_password_file | Path to key password file. |
| insecure | If true, disables SSL verification. |
- Returns
- CURLcode result.
Definition at line 76 of file NHttpRequest.cxx.
◆ throw_curl_error()
| void Ndmspc::NHttpRequest::throw_curl_error |
( |
CURLcode |
res | ) |
const |
|
private |
Throws an exception if a CURL error occurs.
- Parameters
-
Definition at line 208 of file NHttpRequest.cxx.
◆ WriteCallback()
| size_t Ndmspc::NHttpRequest::WriteCallback |
( |
void * |
contents, |
|
|
size_t |
size, |
|
|
size_t |
nmemb, |
|
|
void * |
userp |
|
) |
| |
|
staticprivate |
Callback for writing response data.
- Parameters
-
| contents | Pointer to received data. |
| size | Size of a data unit. |
| nmemb | Number of data units. |
| userp | User pointer (output stream). |
- Returns
- Number of bytes handled.
Definition at line 180 of file NHttpRequest.cxx.
The documentation for this class was generated from the following files: