Created
July 21, 2017 07:51
-
-
Save mkamilov/78e3e548eb5b5a6b8343310dc598bd4d to your computer and use it in GitHub Desktop.
exa,ple for curl with cmake
This file contains 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
cmake_minimum_required (VERSION 3.5) | |
project (curl-demo) | |
set(CURL_LIBRARY "-lcurl") | |
find_package(CURL REQUIRED) | |
add_executable (curl-demo convert.cpp) | |
include_directories(${CURL_INCLUDE_DIR}) | |
target_link_libraries(curl-demo ${CURL_LIBRARIES}) |
This file contains 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
/********* Sample code generated by the curl command line tool ********** | |
* All curl_easy_setopt() options are documented at: | |
* http://curl.haxx.se/libcurl/c/curl_easy_setopt.html | |
************************************************************************/ | |
#include <curl/curl.h> | |
int main(int argc, char *argv[]) | |
{ | |
CURLcode ret; | |
CURL *hnd; | |
struct curl_slist *slist1; | |
slist1 = NULL; | |
slist1 = curl_slist_append(slist1, "content-type: application/json"); | |
hnd = curl_easy_init(); | |
curl_easy_setopt(hnd, CURLOPT_URL, "example.com"); | |
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); | |
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L); | |
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"aaa\":\"123\",\"bbb\":\"456\",\"ccc\":\"\"}"); | |
curl_easy_setopt(hnd, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)69); | |
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.47.0"); | |
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1); | |
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); | |
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L); | |
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L); | |
curl_easy_setopt(hnd, CURLOPT_COOKIEFILE, ""); | |
curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); | |
/* Here is a list of options the curl code used that cannot get generated | |
as source easily. You may select to either not use them or implement | |
them yourself. | |
CURLOPT_WRITEDATA set to a objectpointer | |
CURLOPT_WRITEFUNCTION set to a functionpointer | |
CURLOPT_READDATA set to a objectpointer | |
CURLOPT_READFUNCTION set to a functionpointer | |
CURLOPT_SEEKDATA set to a objectpointer | |
CURLOPT_SEEKFUNCTION set to a functionpointer | |
CURLOPT_ERRORBUFFER set to a objectpointer | |
CURLOPT_STDERR set to a objectpointer | |
CURLOPT_HEADERFUNCTION set to a functionpointer | |
CURLOPT_HEADERDATA set to a objectpointer | |
*/ | |
ret = curl_easy_perform(hnd); | |
curl_easy_cleanup(hnd); | |
hnd = NULL; | |
curl_slist_free_all(slist1); | |
slist1 = NULL; | |
return (int)ret; | |
} | |
/**** End of sample code ****/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment