Created
June 8, 2018 02:18
-
-
Save adonese/595842960cf15b95d3926d2a10adebe1 to your computer and use it in GitHub Desktop.
cURL for Morsal
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
#include <stdio.h> | |
#include <string.h> | |
#include </home/adonese/sources/curl-7.59.0/include/curl/curl.h> | |
int main(void) | |
{ | |
CURL *curl; | |
CURLcode res; | |
static const char *postthis = "moo mooo moo moo"; | |
curl = curl_easy_init(); | |
if(curl) { | |
struct curl_slist *chunk = NULL; | |
chunk = curl_slist_append(chunk, "API-Key: 5d6f54d4-3af4-4ffc-b78d-c2f1ca7827d9"); | |
/* Now let's add the custom header to the curl thing */ | |
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); | |
curl_easy_setopt(curl, CURLOPT_URL, "http://212.0.129.118:8888/terminal_api/workingKey/"); | |
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis); | |
/* if we don't provide POSTFIELDSIZE, libcurl will strlen() by | |
* itself */ | |
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis)); | |
/* Perform the request, res will get the return code */ | |
res = curl_easy_perform(curl); | |
/* Check for errors */ | |
if(res != CURLE_OK) | |
fprintf(stderr, "curl_easy_perform() failed: %s\n", | |
curl_easy_strerror(res)); | |
/* always cleanup */ | |
curl_easy_cleanup(curl); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment