Created
November 16, 2018 02:40
-
-
Save smallnest/cfc85373b5adf392d9554ff70dd387ba 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
| #include <stdio.h> | |
| #include <curl/curl.h> | |
| int main(void) | |
| { | |
| CURL *curl; | |
| CURLcode res; | |
| /* In windows, this will init the winsock stuff */ | |
| curl_global_init(CURL_GLOBAL_ALL); | |
| curl = curl_easy_init(); | |
| if(curl) { | |
| curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:9999"); | |
| curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L); | |
| curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L); | |
| struct curl_slist *headers = NULL; | |
| headers = curl_slist_append(headers, "x-pretty-print: 2"); | |
| headers = curl_slist_append(headers, "content-type: application/json"); | |
| headers = curl_slist_append(headers, "accept: application/json"); | |
| curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); | |
| curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl"); | |
| res = curl_easy_perform(curl); | |
| if(res != CURLE_OK) | |
| fprintf(stderr, "curl_easy_perform() failed: %s\n", | |
| curl_easy_strerror(res)); | |
| 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