Curl-based HTTP(s) client.
#include <http_client.h>
Public Types | |
typedef function< void(const CURLcode, const http::Response &)> | Handler |
Handler type for asynchronous operations. | |
typedef function< void(const CURLcode, const string &error_desc, const http::Response &)> | Handler2 |
Public Member Functions | |
HttpClient () | |
Constructor. | |
~HttpClient () | |
Destructor. | |
DECLARE_CLASS_PTR (HttpClient) | |
CURLcode | Delete (const string &url, const Ptr< const string > &data, size_t timeout_in_ms=0) |
Initiates a DELETE request synchronously. More... | |
CURLcode | Delete (const string &url, const Json &data, size_t timeout_in_ms=0) |
Initiates a application/json DELETE request synchronously. More... | |
void | DeleteAsync (const string &url, const Ptr< const string > &data, const Handler &handler, size_t timeout_in_ms=0) |
Initiates a DELETE request asynchronously. More... | |
void | DeleteAsync (const string &url, const Json &data, const Handler &handler, size_t timeout_in_ms=0) |
Initiates a application/json DELETE request asynchronously. More... | |
void | DeleteAsync2 (const string &url, const Ptr< const string > &data, const Handler2 &handler, size_t timeout_in_ms=0) |
Initiates a DELETE request asynchronously. More... | |
void | DeleteAsync2 (const string &url, const Json &data, const Handler2 &handler, size_t timeout_in_ms=0) |
Initiates a application/json DELETE request asynchronously. More... | |
const string & | error_message () const |
Returns a stored error messasge. More... | |
CURLcode | Get (const string &url, size_t timeout_in_ms=0) |
Initiates a GET request synchronously. More... | |
void | GetAsync (const string &url, const Handler &handler, size_t timeout_in_ms=0) |
Initiates a GET request asynchronously. More... | |
void | GetAsync2 (const string &url, const Handler2 &handler, size_t timeout_in_ms=0) |
Initiates a GET request asynchronously. More... | |
CURL * | handle () |
Returns an underlying curl handle. More... | |
CURLcode | Post (const string &url, const Ptr< const string > &data, size_t timeout_in_ms=0) |
Initiates a POST request synchronously. More... | |
CURLcode | Post (const string &url, const Json &data, size_t timeout_in_ms=0) |
Initiates a application/json POST request synchronously. More... | |
CURLcode | Post (const string &url, const curl_httppost *data, size_t timeout_in_ms=0) |
Initiates a multipart form POST request synchronously. More... | |
void | PostAsync (const string &url, const Ptr< const string > &data, const Handler &handler, size_t timeout_in_ms=0) |
Initiates a POST request asynchronously. More... | |
void | PostAsync (const string &url, const Json &data, const Handler &handler, size_t timeout_in_ms=0) |
Initiates a application/json POST request asynchronously. More... | |
void | PostAsync (const string &url, const curl_httppost *data, const Handler &handler, size_t timeout_in_ms=0) |
Initiates a multipart form POST request synchronously. More... | |
void | PostAsync2 (const string &url, const Ptr< const string > &data, const Handler2 &handler, size_t timeout_in_ms=0) |
Initiates a POST request asynchronously. More... | |
void | PostAsync2 (const string &url, const Json &data, const Handler2 &handler, size_t timeout_in_ms=0) |
Initiates a application/json POST request asynchronously. More... | |
void | PostAsync2 (const string &url, const curl_httppost *data, const Handler2 &handler, size_t timeout_in_ms=0) |
Initiates a multipart form POST request synchronously. More... | |
CURLcode | Put (const string &url, const Ptr< const string > &data, size_t timeout_in_ms=0) |
Initiates a PUT request synchronously. More... | |
CURLcode | Put (const string &url, const Json &data, size_t timeout_in_ms=0) |
Initiates a application/json PUT request synchronously. More... | |
void | PutAsync (const string &url, const Ptr< const string > &data, const Handler &handler, size_t timeout_in_ms=0) |
Initiates a PUT request asynchronously. More... | |
void | PutAsync (const string &url, const Json &data, const Handler &handler, size_t timeout_in_ms=0) |
Initiates a application/json PUT request asynchronously. More... | |
void | PutAsync2 (const string &url, const Ptr< const string > &data, const Handler2 &handler, size_t timeout_in_ms=0) |
Initiates a PUT request asynchronously. More... | |
void | PutAsync2 (const string &url, const Json &data, const Handler2 &handler, size_t timeout_in_ms=0) |
Initiates a application/json PUT request asynchronously. More... | |
void | ResetHeader () |
Reset the header to the default state. | |
const http::Response & | response () const |
Returns a stored response. More... | |
void | set_verbose (bool on) |
Turns on/off verbose logging. More... | |
void | SetHeader (const string &key, const string &value) |
Set HTTP header. More... | |
void | UnsetHeader (const string &key) |
Removes a header item already set. More... | |
CURLcode fun::HttpClient::Delete | ( | const string & | url, |
const Ptr< const string > & | data, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | delete data in string that is assumed properly encodded. |
CURLcode fun::HttpClient::Delete | ( | const string & | url, |
const Json & | data, | ||
size_t | timeout_in_ms = 0 |
||
) |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | in Json. |
void fun::HttpClient::DeleteAsync | ( | const string & | url, |
const Ptr< const string > & | data, | ||
const Handler & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | delete data in string. The call must perform encoding. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::DeleteAsync | ( | const string & | url, |
const Json & | data, | ||
const Handler & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | in Json. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::DeleteAsync2 | ( | const string & | url, |
const Ptr< const string > & | data, | ||
const Handler2 & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | delete data in string. The call must perform encoding. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::DeleteAsync2 | ( | const string & | url, |
const Json & | data, | ||
const Handler2 & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | in Json. |
handler | Handler functor to be invoked once operation is done. |
const string& fun::HttpClient::error_message | ( | ) | const |
CURLcode fun::HttpClient::Get | ( | const string & | url, |
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
void fun::HttpClient::GetAsync | ( | const string & | url, |
const Handler & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::GetAsync2 | ( | const string & | url, |
const Handler2 & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
handler | Handler functor to be invoked once operation is done. |
CURL* fun::HttpClient::handle | ( | ) |
If you need to tweak curl's http option, you can pass this handle to curl_easy_setopt(...)
CURLcode fun::HttpClient::Post | ( | const string & | url, |
const Ptr< const string > & | data, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | post data in string that is assumed properly encodded. |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | in Json. |
CURLcode fun::HttpClient::Post | ( | const string & | url, |
const curl_httppost * | data, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | curl_httppost pointer generated by curl_formadd(). |
void fun::HttpClient::PostAsync | ( | const string & | url, |
const Ptr< const string > & | data, | ||
const Handler & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | post data in string. The call must perform encoding. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::PostAsync | ( | const string & | url, |
const Json & | data, | ||
const Handler & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | in Json. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::PostAsync | ( | const string & | url, |
const curl_httppost * | data, | ||
const Handler & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | curl_httppost pointer generated by curl_formadd(). |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::PostAsync2 | ( | const string & | url, |
const Ptr< const string > & | data, | ||
const Handler2 & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | post data in string. The call must perform encoding. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::PostAsync2 | ( | const string & | url, |
const Json & | data, | ||
const Handler2 & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | in Json. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::PostAsync2 | ( | const string & | url, |
const curl_httppost * | data, | ||
const Handler2 & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | curl_httppost pointer generated by curl_formadd(). |
handler | Handler functor to be invoked once operation is done. |
CURLcode fun::HttpClient::Put | ( | const string & | url, |
const Ptr< const string > & | data, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | post data in string that is assumed properly encodded. |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | in Json. |
void fun::HttpClient::PutAsync | ( | const string & | url, |
const Ptr< const string > & | data, | ||
const Handler & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | put data in string. The call must perform encoding. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::PutAsync | ( | const string & | url, |
const Json & | data, | ||
const Handler & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | in Json. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::PutAsync2 | ( | const string & | url, |
const Ptr< const string > & | data, | ||
const Handler2 & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
url | string target url. (e.g., https://www.google.com/path/) |
data | put data in string. The call must perform encoding. |
handler | Handler functor to be invoked once operation is done. |
void fun::HttpClient::PutAsync2 | ( | const string & | url, |
const Json & | data, | ||
const Handler2 & | handler, | ||
size_t | timeout_in_ms = 0 |
||
) |
Content type is set to application/json.
url | string target url. (e.g., https://www.google.com/path/) |
data | in Json. |
handler | Handler functor to be invoked once operation is done. |
const http::Response& fun::HttpClient::response | ( | ) | const |
void fun::HttpClient::set_verbose | ( | bool | on | ) |
on | true/false |
There can be multiple values with the same key.
key | string HTTP header key. |
value | string HTTP header value. |
void fun::HttpClient::UnsetHeader | ( | const string & | key | ) |
key | string HTTP header key |