libcurl在嵌入式设备C 的使用
来源:互联网 发布:淘宝运动衣 编辑:程序博客网 时间:2024/06/04 21:54
最近用海思hi3518E开发了个wifi摄录一体机,现在要用http实现信息推送功能,比如在设备发生报警录像时就会推送一条信息“有异常入侵!”和一张抓拍图像到服务器,然后当客户的手机上网时,就会受到推送的信息。在网上下载了curl的开源库,可以用C实现http功能。
一、curl库的编译
curl的下载地址是http://curl.haxx.se/download.html,详细的编译步骤参考http://curl.haxx.se/docs/install.html。在这里简单说明我的编译步骤:
>tar xvzf curl-7.37.0.tar.gz
>cd curl-7.37.0
>./configure --host=arm-none-linux --prefix=/home/hank/http/hisi_http CC=arm-hisiv100nptl-linux-gcc --disable-shared --enable-static --without-libidn --without-ssl --without-librtmp --without-gnutls --without-nss --without-libssh2 --without-zlib --without-winidn --disable-rtsp --disable-ldap --disable-ldaps --disable-ipv6
>make
>make install
其中,CC指定编译器,--prefix=/home/hank/http/hisi_http指定make install时库的存放路径,这里编译成静态库,去掉了其中的一些功能。
二、curl库的使用
下面的例子参考了http://blog.csdn.net/sxwyf248/article/details/7984776
在C程序中模拟要实现的html为:
<html><body><form action="http://150.10.20.167:8080/TestJspSmartUpload/do_upload.jsp" method="post" enctype="multipart/form-data"> File:<input type="file" name="sendfile" /><br/> FileName:<input type="text" name="filename" /><br/> <input type="submit" name="submit" value="Submit" /> </form> </body></html>
C程序代码为:
#include <stdio.h> #include <string.h> #include <curl.h> int main(int argc, char *argv[]) { CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "sendfile", CURLFORM_FILE, "man.jpg", CURLFORM_END); /* Fill in the filename field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "filename", CURLFORM_COPYCONTENTS, "man.jpg", CURLFORM_END); /* Fill in the submit field too, even if this is rarely needed */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "Submit", CURLFORM_END); curl = curl_easy_init(); /* initalize custom header list (stating that Expect: 100-continue is not wanted */ headerlist = curl_slist_append(headerlist, buf); if(curl) { /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, "http://150.10.20.167:8080/TestJspSmartUpload/do_upload.jsp"); if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) ) /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10); /* 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); /* then cleanup the formpost chain */ curl_formfree(formpost); /* free slist */ curl_slist_free_all (headerlist); } return 0; } 编译链接:arm-hisiv100nptl-linux-gcc -o upload upload.c -I./include/curl -L./lib -lcurl -lrt
该例子在平台上运行正常,http服务器能收到图像文件。
- libcurl在嵌入式设备C 的使用
- libcurl在嵌入式设备C 的使用
- linux c libcurl的简单使用
- linux c libcurl的简单使用
- linux c libcurl的简单使用
- linux c libcurl的简单使用
- linux c libcurl的简单使用
- libcurl的C语言接口使用过程
- linux c libcurl的简单使用
- c libcurl 基本使用
- 在嵌入式设备中使用protobuf
- 在C语言程序中使用cURL库(libcurl)
- linux C libcurl https 使用
- libcurl的使用
- libcurl的使用
- libcurl的使用总结
- libcurl的使用
- libcurl的使用总结
- 爬虫资料收集
- hive SQL优化之distribute by和sort by
- 求素数
- 机器不会有错的
- 找工作-基本查找排序算法总结
- libcurl在嵌入式设备C 的使用
- 笔记本重装系统后黑屏,但可以听到进入系统的声音
- JavaScript里的依赖注入
- js 绘制的rose
- Android读取图片资源的4中方式
- hdu 2066 一个人的旅行(Dijkstra)
- ubuntu下解决Ctrl-Alt-down in Gnome 3.8 和Eclipse快捷键冲突问题
- cocos2dx lua 和 quickcocos2dx lua需知(持续添加)
- 职场分享:职场中如何释放自己的工作压力