libcurl库的简介(二)
下面是使用libcurl库实现文件上传的一个实例: void CDataProcess::sendFileToServer(void)
{
string netIp = strNetUrl + "SaveFile"; for (int i = ; i < taskZipVector.size(); ++i)
{
string strFileName = taskZipVector[i];
string strFilePath = strAppPath + "\\Task\\"+ strFileName + ".zip"; CURL *curl = NULL;
string readFile = ""; struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headerlist=NULL;
static const char buf[] = "Expect:"; if(- == _access(strFilePath.c_str(),))
{
return ;
}
curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "fileContent",
CURLFORM_FILE, strFilePath.c_str(),
CURLFORM_END); curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "filename",
CURLFORM_COPYCONTENTS, strFileName.c_str(),
CURLFORM_END); curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END); curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buf);
curl_easy_setopt(curl, CURLOPT_URL, netIp.c_str()); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK)
{
//CFuncs::WriteLogInfo(SLT_ERROR, "finshUpdate() curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
return ;
} isSendedFlag = ; //设置已传送文件标志
curl_easy_cleanup(curl);
curl_formfree(formpost);
curl_slist_free_all (headerlist);
}
}
struct curl_httppost {
struct curl_httppost *next; /* next entry in the list */
char *name; /* pointer to allocated name */
long namelength; /* length of name length */
char *contents; /* pointer to allocated data contents */
long contentslength; /* length of contents field, see also
CURL_HTTPPOST_LARGE */
char *buffer; /* pointer to allocated buffer contents */
long bufferlength; /* length of buffer field */
char *contenttype; /* Content-Type */
struct curl_slist *contentheader; /* list of extra headers for this form */
struct curl_httppost *more; /* if one field name has more than one
file, this link should link to following
files */
long flags; /* as defined below */
/* specified content is a file name */
#define CURL_HTTPPOST_FILENAME (1<<0)
/* specified content is a file name */
#define CURL_HTTPPOST_READFILE (1<<1)
/* name is only stored pointer do not free in formfree */
#define CURL_HTTPPOST_PTRNAME (1<<2)
/* contents is only stored pointer do not free in formfree */
#define CURL_HTTPPOST_PTRCONTENTS (1<<3)
/* upload file from buffer */
#define CURL_HTTPPOST_BUFFER (1<<4)
/* upload file from pointer contents */
#define CURL_HTTPPOST_PTRBUFFER (1<<5)
/* upload file contents by using the regular read callback to get the data and
pass the given pointer as custom pointer */
#define CURL_HTTPPOST_CALLBACK (1<<6)
/* use size in 'contentlen', added in 7.46.0 */
#define CURL_HTTPPOST_LARGE (1<<7)
char *showfilename; /* The file name to show. If not set, the
actual file name will be used (if this
is a file part) */
void *userp; /* custom pointer used for
HTTPPOST_CALLBACK posts */
curl_off_t contentlen; /* alternative length of contents
field. Used if CURL_HTTPPOST_LARGE is
set. Added in 7.46.0 */
};
struct curl_slist {
char *data;
struct curl_slist *next;
};
CURL_EXTERN CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post,.);
libcurl库的简介(二)的更多相关文章
- libcurl库的简介(一)
一.Libcurl库简介 LibCurl是免费的客户端URL传输库,支持FTP,FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE ,LDAP ...
- Python数据分析Numpy库方法简介(二)
数据分析图片保存:vg 1.保存图片:plt.savefig(path) 2.图片格式:jpg,png,svg(建议使用,不失真) 3.数据存储格式: excle,csv csv介绍 csv就是用逗号 ...
- Linux之Libcurl库的介绍与应用20170509
一.LibCurl简介 LibCurl是免费的客户端URL传输库,支持FTP,FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE ,LDAP等 ...
- C++ 用libcurl库进行http通讯网络编程
使用libcurl完成http通讯,很方便而且是线程安全,转载一篇比较好的入门文章 转载自 http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724 ...
- C++ 用libcurl库进行http通讯网络编程(转)
转载:http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三. ...
- C++ 用libcurl库进行http通讯网络编程[转]
http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三.cur ...
- C/C++ 用libcurl库进行http通讯网络编程
C/C++ 用libcurl库进行http通讯网络编程 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三.curl_easy_setopt函数部分选项介绍 四.curl_easy_p ...
- C++ 用libcurl库进行http 网络通讯编程
一.LibCurl基本编程框架libcurl是一个跨平台的网络协议库,支持http, https, ftp, gopher, telnet, dict, file, 和ldap 协议.libcur ...
- Raphael Js矢量库API简介:
Raphael Js矢量库API简介:Raphael Javascript 是一个 Javascript的矢量库. 2010年6月15日,著名的JavaScript库ExtJS与触摸屏代码库项目jQT ...
随机推荐
- Unity3D制作3D虚拟漫游场景(二)
传送门: Unity3D制作3D虚拟漫游场景(一) -------------------------------------------------------------------------- ...
- JS高级---沙箱
沙箱 沙箱: 环境, 黑盒, 在一个虚拟的环境中模拟真实世界, 做实验, 实验结果和真实世界的结果是一样, 但是不会影响真实世界 全局变量 var num=10; console.log(nu ...
- JUC-多线程锁
多线程锁的练习题 1.标准访问,先打印短信还是邮件 class Phone { public synchronized void sendSMS() throws Exception { Thread ...
- windows下pycharm输入法跟随设置
参考网址:http://www.itdaan.com/blog/2018/05/20/90e64dae077f8ad7fa70bc9c3c8ab422.html
- K-NN graph
tasks: 1. unsupervised knn https://scikit-learn.org/stable/modules/neighbors.html#unsupervised-neigh ...
- print format
python基础_格式化输出(%用法和format用法) name = 'jack' age = 18 sex = 'man' job = "IT" salary = 9999.9 ...
- ASP.NET Core Web API中Startup的使用技巧
Startup类和服务配置 STARTUP CLASS AND THE SERVICE CONFIGURATION 在 Startup 类中,有两个方法:ConfigureServices 是用于 ...
- VC++编译选项
-优化- /O1 最小化空间 minimize space /Op[-] 改善浮点数一致性 improve floating-pt consistency /O2 最大化速度 maximize spe ...
- IntelliJ IDEA 2017.3尚硅谷-----插件的使用
在 IntelliJ IDEA 的安装讲解中我们其实已经知道,IntelliJ IDEA 本身很多功能也都 是通过插件的方式来实现的.官网插件库:https://plugins.jetbrains.c ...
- python selenium设计模式POM
POM模式是什么 页面对象模型(POM)是一种设计模式,用来管理维护一组web元素集的对象库 在POM模式下,应用程序的每一个页面都有一个对的page class 每一个page class维护着该w ...