Created
November 30, 2016 09:34
-
-
Save ictlyh/9902a24d8465bcd7049041930c8565a3 to your computer and use it in GitHub Desktop.
Demo of posting data to webpage via lib curl.
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
/* | |
* Demo of posting data to webpage via lib curl. | |
* Build: gcc curl-post.c -o curl-post -lcurl | |
* Run: ./curl-post | |
*/ | |
#include <curl/curl.h> | |
#include <stdio.h> | |
int main(void) { | |
CURL *curl; | |
CURLcode res; | |
/* In windows, this will init the winsock stuff */ | |
curl_global_init(CURL_GLOBAL_ALL); | |
/* get a curl handle */ | |
curl = curl_easy_init(); | |
if(curl) { | |
/* Set the URL that is about to receive our POST. */ | |
curl_easy_setopt(curl, CURLOPT_URL, "http://baidu.com"); | |
/* Now specify the POST data */ | |
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=count&value=10000"); | |
/* Perform the request, res will get the return code */ | |
res = curl_easy_perform(curl); | |
/* Check for errors */ | |
if(res != CURLE_OK) | |
fprintf(stdout, "curl_easy_perform() failed: %s\n", | |
curl_easy_strerror(res)); | |
/* always cleanup */ | |
curl_easy_cleanup(curl); | |
} | |
curl_global_cleanup(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment