1.为实现树莓派摄像头人脸识别所以需要用到此库
2.libcurl库下载地址:https://github.com/curl/curl/releases/tag/curl-7_71_1
将压缩包已到ubuntu虚拟机解压
进入解压后的文件夹配置:./configure --prefix=$PWD/_install --host = arm-linux-greng。。。。
(如果./configure 后不接 --prefix默认安装在/usr/local低下。在链库的环境变量里)
make
make inatall
在文件夹下生成了一个_install文件夹
demo.c
#include <stdio.h> #include <curl/curl.h> bool getUrl(char *filename) { CURL *curl; CURLcode res; FILE *fp; if ((fp = fopen(filename, "w")) == NULL) // 返回结果用文件存储 return false; struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Accept: Agent-007"); curl = curl_easy_init(); // 初始化 if (curl) { //curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080");// 代理 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);// 改协议头 curl_easy_setopt(curl, CURLOPT_URL,"http://www.baidu.com"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); //将返回的http头输出到fp指向的文件 curl_easy_setopt(curl, CURLOPT_HEADERDATA, fp); //将返回的html主体数据输出到fp指向的文件 res = curl_easy_perform(curl); // 执行 if (res != 0) { curl_slist_free_all(headers); curl_easy_cleanup(curl); } fclose(fp); return true; } } bool postUrl(char *filename) { CURL *curl; CURLcode res; FILE *fp; if ((fp = fopen(filename, "w")) == NULL) return false; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "&logintype=uid&u=xieyan&psw=xxx86"); // 指定post内容 //curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080"); curl_easy_setopt(curl, CURLOPT_URL, " http://mail.sina.com.cn/cgi-bin/login.cgi "); // 指定url curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); res = curl_easy_perform(curl); curl_easy_cleanup(curl); } fclose(fp); return true; } int main(void) { getUrl("/tmp/get.html"); postUrl("/tmp/post.html"); }
加入openssl支持https访问,先把他删了(学习过程,供自己参考)
make
make install
如果:openssl不存在可参考:
标签:fp,setopt,libcurl,res,openssl,编译,easy,curl,CURLOPT From: https://www.cnblogs.com/hetaoBlog/p/17165928.html