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 ...
随机推荐
- 想要学好Git,应该掌握哪些基础知识?
说到Git,作为程序员的你,在项目开发中一定会使用到或将来也一定会使用到的,但是我相信,很多在使用Git的人,都只是停留一些简单的操作上,比如提交(commit).拉取(pull).推送(push). ...
- 杭电oj_1713——相遇周期(java实现)
question:相遇周期 思路: 首先将两个分数化为最简形式(也就是分子分母同时除以最大公约数) 然后题意是要求两个分数的最小公倍数 借助以下两个公式,就可以求出结果 1.最小公倍数*最大公约数 = ...
- mysql慢日志分析pt-query-digest
一.pt-query-digest 安装pt-query-digest yum install perl-DBI yum install perl-DBD-MySQL yum install perl ...
- pve apt-get update error 升级报错-文章未完工和验证
pve: apt-get update error 升级报错 提示如下报错 Hit: http://security.debian.org buster/updates InRelease Hit: ...
- C# 后台调用http,post访问url,获取数据
1.封装post方法发送 using System; using System.Collections.Generic; using System.IO; using System.Linq; usi ...
- 使用VSCode的Remote-SSH连接Linux进行远程开发
安装Remote-SSH并配置 首先打开你的VSCode,找到Extensions,搜索Remote,下载Remote-Developoment插件,会自动安装其他的Remote插件,其中会包含Rem ...
- 【sql】sql必知必会_02
chapter10 - 常用的sql标准有哪些,在SQL92中是如何使用连接的? sql两个主要的标准sql92.sql95: sql92中的五种连接方式: a.笛卡尔积:是一个数学运算,两个集合X和 ...
- Asp.net的WebForm的落后技术
本文链接:https://bbs.csdn.net/topics/392077893 因为webform确实,企图通过在html标签中的runat="server",在iis接受请 ...
- oracle中日期的函数的使用
--oracle中trunc()函数的用法 .select trunc(sysdate) from dual --2019-6-18 今天的日期为209-6-18 .select trunc(sysd ...
- 新的存储网站,和存储单元dropbox
新的存储网站,和存储单元dropbox 待办 https://www.dropbox.com/home google 登陆 google邮箱 密码 521google 但是免费存储量只有2G goog ...