Skip to content

Commit 71b7a0b

Browse files
committed
Added Cookie Feature. Now you can use Cookies with this restClient.
1 parent 0d590e5 commit 71b7a0b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

source/restclient.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ RestClient::response RestClient::get(const std::string& url)
6262
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, RestClient::header_callback);
6363
/** callback object for headers */
6464
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &ret);
65+
/** enable cookies */
66+
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie");
67+
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
6568
/** perform the actual query */
6669
res = curl_easy_perform(curl);
6770
if (res != CURLE_OK)
@@ -127,6 +130,9 @@ RestClient::response RestClient::post(const std::string& url,
127130
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, RestClient::header_callback);
128131
/** callback object for headers */
129132
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &ret);
133+
/** enable cookies */
134+
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie");
135+
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
130136
/** set content-type header */
131137
curl_slist* header = NULL;
132138
header = curl_slist_append(header, ctype_header.c_str());
@@ -204,6 +210,9 @@ RestClient::response RestClient::put(const std::string& url,
204210
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, RestClient::header_callback);
205211
/** callback object for headers */
206212
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &ret);
213+
/** enable cookies */
214+
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie");
215+
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
207216
/** set data size */
208217
curl_easy_setopt(curl, CURLOPT_INFILESIZE,
209218
static_cast<long>(up_obj.length));
@@ -272,6 +281,9 @@ RestClient::response RestClient::del(const std::string& url)
272281
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, RestClient::header_callback);
273282
/** callback object for headers */
274283
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &ret);
284+
/** enable cookies */
285+
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie");
286+
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
275287
/** perform the actual query */
276288
res = curl_easy_perform(curl);
277289
if (res != CURLE_OK)

0 commit comments

Comments
 (0)