安装
sudo apt-get install libcurl4-openssl-dev
代码包含头文件
#include <curl/curl.h>
编译
gcc -o xxx xxx.c -lcurl
sample code
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
char url[] = "http://localhost/test.php";
//char user[] = "xxx";
//char password[] = "xxx";
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
//curl_easy_setopt(curl, CURLOPT_USERNAME, user);
//curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}