-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebclient.c
More file actions
44 lines (33 loc) · 1.01 KB
/
Copy pathwebclient.c
File metadata and controls
44 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//#include <curl/easy.h>
#include <stdio.h>
#include <curl/curl.h>
size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userdata){
size_t total_size = size*nmemb;
fwrite(ptr, size, nmemb, stdout);
return total_size;
}
int main(int argc, char *argv[]){
if(argc<2){
printf("USAGE: ./client <api_key>\n");
return 1;
}
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl){
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, argv[1]);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
// Perform the request
res = curl_easy_perform(curl);
// Check for errors
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
// Cleanup
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}