-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall.c
More file actions
40 lines (33 loc) · 995 Bytes
/
call.c
File metadata and controls
40 lines (33 loc) · 995 Bytes
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
#include <stdlib.h>
#include <stdio.h>
#include <curl/curl.h>
unsigned write_cb(char *in, unsigned size, unsigned nmemb, void* out)
{
uint r;
r = size * nmemb;
printf("Response: \n%s\n",in);
return(r);
}
int main(int argc, char** argv) {
if(argc != 2) {
fprintf(stderr, "Sorry, buddy. Try again.\n\tUSAGE: %s URL\n",argv[0]);
return -1;
}
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "id=1");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
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;
}