Category : libcurl

I am using libcurl in a c++ program to send some data in a POST HTTP request. Basically I am doing this after I receive a specific event: ctx.easy = curl_easy_init(); if (curl_multi_add_handle(ctx.curlm, ctx.easy) != CURLM_OK) { printf("Error with curl_multi_add_handle(%p).n", ctx.curlm); exit(EXIT_FAILURE); } curl_easy_reset(ctx.easy); curl_easy_setopt(ctx.easy, CURLOPT_URL, url); curl_easy_setopt(ctx.easy, CURLOPT_POST, 1L); curl_easy_setopt(ctx.easy, CURLOPT_COPYPOSTFIELDS, json); curl_easy_setopt(ctx.easy, CURLOPT_VERBOSE, ..

Read more

I have a function that attempts to find a cookie, std::string BothRequest::find_cookie(CURL*& handle, std::string cookie_name) { struct curl_slist* cookies = NULL; CURLcode res = curl_easy_getinfo(handle, CURLINFO_COOKIELIST, &cookies); if (res != CURLE_OK) { return std::string(); } /* a linked list of cookies in cookie file format */ struct curl_slist* each = cookies; while (each) { std::cout ..

Read more

I have a function that attempts to find a cookie: std::string BothRequest::find_cookie(CURL*& handle, std::string cookie_name) { struct curl_slist* cookies = NULL; CURLcode res = curl_easy_getinfo(handle, CURLINFO_COOKIELIST, &cookies); if (res != CURLE_OK) { return std::string(); } /* a linked list of cookies in cookie file format */ struct curl_slist* each = cookies; while (each) { std::cout ..

Read more

Im downloading/reading data from my database with Curl and the following code: static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { ((std::string*)userp)->append((char*)contents, size * nmemb); return size * nmemb; } void Url(std::string url, std::string mode, std::string json) { CURLcode ret; CURL *curl; struct curl_slist *slist1; curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, ..

Read more

typedef struct ResponseBody { size_t memorySize = BUFSIZ; size_t dataSize{}; char *bodyMemory = new char[BUFSIZ]; public: ~ResponseBody(); } ResponseBody; ResponseBody::~ResponseBody() { delete[] this->bodyMemory; } size_t get_containers_callback(const char *buff, size_t size, size_t buff_size, void *data) { auto *body = (ResponseBody *) data; size_t needMemory = body->dataSize + buff_size; if (needMemory > body->memorySize) { auto *newMemory = ..

Read more

Basically, I’m just trying to run this curl command on my C++ application with libcurl. curl http://127.0.0.1:8384/rest/events -H "X-API-Key: WuCS7KQtyoRxbWDZ4zsSbjUdU4T" The command works perfectly fine on the command prompt. But when I try to use it with libcurl, I keep getting the 400 Bad Request: invalid header name error. I browsed through a few other ..

Read more