curl http libcurl 功能使用
/*
* This example shows a HTTP PUT operation. PUTs a file given as a command
* line argument to the URL also given on the command line.
*
* This example also uses its own read callback.
*
* Here's an article on how to setup a PUT handler for Apache:
* http://www.apacheweek.com/features/put
*/
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
{
size_t retcode;
curl_off_t nread;
/* in real-world cases, this would probably get this data differently
as this fread() stuff is exactly what the library already would do
by default internally */
retcode = fread(ptr, size, nmemb, (FILE*)stream);
nread = (curl_off_t)retcode;
fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
" bytes from file\n", nread);
return retcode;
}
//http协议上传
void fileUploadHttp()
{
CURL *curl;
CURLcode res;
FILE * hd_src;
struct stat file_info;
QString locale = ui->lineEdit_path->text();
char *file = locale.toLatin1().data();
QFileInfo fileInfo(locale);
QString fileName = fileInfo.fileName();
QString remote = "http://www.example.com/upload.php?filename=" + fileName;
char *remote_url = remote.toLatin1().data(); //服务器路径
/* get the file size of the local file */
stat(file, &file_info);
/* get a FILE * of the same file, could also be made with
fdopen() from the previous descriptor, but hey this is just
an example! */
hd_src = fopen(file, "rb");
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
/* get a curl handle */
curl = curl_easy_init();
if(curl) {
/* we want to use our own read function */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* HTTP PUT please */
curl_easy_setopt(curl, CURLOPT_PUT, 1L);
/* specify target URL, and note that this URL should include a file
name, not only a directory */
curl_easy_setopt(curl, CURLOPT_URL, remote_url);
/* now specify which file to upload */
curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
/* provide the size of the upload, we specicially typecast the value
to curl_off_t since we must be sure to use the correct data size */
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);
/* Now run off and do what you've been told! */
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);
}
fclose(hd_src); /* close the local file */
curl_global_cleanup();
}
curl http libcurl 功能使用的更多相关文章
- curl ftp libcurl 功能使用
struct FtpFile { const char *filename; FILE *stream; }; static size_t my_fwrite(void *buffer, size_t ...
- curl tftp libcurl 功能使用
#include <curl/curl.h> static size_t read_callback(void *ptr, size_t size, size_t nmemb, void ...
- curl sftp libcurl 功能使用
#include <curl/curl.h> #undef DISABLE_SSH_AGENT struct FtpFile { const char *filename; FILE *s ...
- cURL 是一个功能强大的PHP库。
使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓取的网页,然后就可以以程序的方式得到你想要的数据了.无论是你想从从一个链接上取部分数据,或是取一个XML文件并把 ...
- curl smtp libcurl 邮件功能使用
/* * For an SMTP example using the multi interface please see smtp-multi.c. */ /* The libcurl option ...
- CURL 和LIBCURL C++代码 上传本地文件,好不容易碰到了这种折腾我几天的代码
解决了什么问题:curl在使用各种方式上传文件到服务器.一般的文件上传是通过html表单进行的,通过CURL可以不经过浏览器,直接在服务器端模拟进行表单提交,完成POST数据.文件上传等功能. 服务器 ...
- 海思平台交叉编译curl支持SSL功能
1.准备工具 1).交叉编译工具 2).下载libcurl和openssl源代码,我使用的是(openssl-1.0.2o.tar,curl-7.59.0.tar) 3).查看cpu详细 ~ # ca ...
- 使用curl,libcurl访问Https
编译curl,libcurl 下载curl源码(git clone https://github.com/curl/curl),在目录curl\winbuild\BUILD.WINDOWS.txt文件 ...
- About libcurl and cURL in PHP
今天在学习php时遇到要调用curl 库函数对特定url字符串进行访问操作,需要自己写一个方法进行调用,之前在linux系统中也有用到cURL 命令行工具执行对相关资源的获取,在wiki上找到了如下的 ...
随机推荐
- SSM框架之Mybatis(5)数据库连接池及事务
Mybatis(5)数据库连接池及事务 1.Mybatis连接池 Mybatis 中也有连接池技术,但是它采用的是自己的连接池技术.在 Mybatis 的 SqlMapConfig.xml 配置文 ...
- 安全意识第八期丨OMG!发个帖子竟然摊上大事了
互联网时代,话在网上说.钱在网上花.事在网上办,这早已成为一种习惯,越来越多的人也倾向于通过网络来获取信息. 借助现代信息技术,网络传播者通过即时通讯工具.微博.朋友圈等渠道发布信息,虽然传播起来更便 ...
- SAP MM 供应商无英文名称,ME21N里却带出了英文名字?
SAP MM 供应商无英文名称,ME21N里却带出了英文名字? 近日收到客户业务用户上报的一个问题说ME21N的时候,供应商101071的名字怎么是英文名字,实际上供应商主数据里是没有这个英文名字, ...
- 洛谷 P5658 括号树
\(50pts\) #include <cstdio> #include <cstring> #include <iostream> #include <al ...
- [ Python入门教程 ] Python文件基本操作_shutil模块
shutil模块是对os模块中文件操作的补充,提供文件和目录的移动.复制.打包.压缩.解压等功能 shutil常用函数 shutil.copyfile(src, dst) 复制文件, 如果ds ...
- 无限可能,Elasticsearch(一)
这个世界已然被数据淹没.多年来,我们系统间流转和产生的大量数据已让我们不知所措. 现有的技术都集中在如何解决数据仓库存储以及如何结构化这些数据. 这些看上去都挺美好,直到你实际需要基于这些数据实时做决 ...
- Win32 程序开发:窗口类结构体 WNDCLASS 和 WNDCLASSEX
一.窗口类结构体简介 窗口类结构体包含了窗口的各种参数信息.比如:窗口的图标.菜单栏.背景颜色.窗口的消息处理等等. 窗口类结构体有两个:WNDCLASS(早期版本) 和 WNDCLASSEX(新版本 ...
- 使用Kafka建立可靠的高性能分布式消息传递基础结构
在优锐课学习中了解到,我们可以看到实施资源适配器以将Kafka与企业Java解决方案集成.码了很多专业的相关知识, 分享给大家参考学习. 由于世界已经变得移动化,因此应用程序现在必须实时提供数据. 不 ...
- 前端笔记之Vue(五)TodoList实战&拆分store&跨域&练习代理跨域
一.TodoList 1.1安装依赖 安装相关依赖: npm install --save-dev webpack npm install --save-dev babel-loader babel- ...
- Flink1.7.2安装部署的几种方式
原文链接:https://blog.csdn.net/a_drjiaoda/article/details/88037282 前言:Flink的运行一般分为三种模式,即local.Standalone ...