Created
November 17, 2016 09:14
-
-
Save mr5z/2e51f44f38a1526b3447490c4167b4b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Http { | |
public: | |
// omitted other code | |
/** | |
* @param callback(CURLcode, response) | |
*/ | |
template<typename F> | |
void request(std::string url, F &callback) { | |
curl_easy_reset(handle); | |
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &response); | |
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &writeCallback); | |
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); | |
CURLcode res = curl_easy_perform(curl); | |
callback(res, response); | |
} | |
private: | |
size_t writeCallback(void *contents, size_t size, size_t nmemb, std::string *data) { | |
response.append((char*)contents, size * nmemb); | |
return size * nmemb; | |
} | |
private: | |
CURL *handle; | |
std::string response; | |
static int curlInstanceCount; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment