/*
* 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 功能使用的更多相关文章

  1. curl ftp libcurl 功能使用

    struct FtpFile { const char *filename; FILE *stream; }; static size_t my_fwrite(void *buffer, size_t ...

  2. curl tftp libcurl 功能使用

    #include <curl/curl.h> static size_t read_callback(void *ptr, size_t size, size_t nmemb, void ...

  3. curl sftp libcurl 功能使用

    #include <curl/curl.h> #undef DISABLE_SSH_AGENT struct FtpFile { const char *filename; FILE *s ...

  4. cURL 是一个功能强大的PHP库。

    使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓取的网页,然后就可以以程序的方式得到你想要的数据了.无论是你想从从一个链接上取部分数据,或是取一个XML文件并把 ...

  5. curl smtp libcurl 邮件功能使用

    /* * For an SMTP example using the multi interface please see smtp-multi.c. */ /* The libcurl option ...

  6. CURL 和LIBCURL C++代码 上传本地文件,好不容易碰到了这种折腾我几天的代码

    解决了什么问题:curl在使用各种方式上传文件到服务器.一般的文件上传是通过html表单进行的,通过CURL可以不经过浏览器,直接在服务器端模拟进行表单提交,完成POST数据.文件上传等功能. 服务器 ...

  7. 海思平台交叉编译curl支持SSL功能

    1.准备工具 1).交叉编译工具 2).下载libcurl和openssl源代码,我使用的是(openssl-1.0.2o.tar,curl-7.59.0.tar) 3).查看cpu详细 ~ # ca ...

  8. 使用curl,libcurl访问Https

    编译curl,libcurl 下载curl源码(git clone https://github.com/curl/curl),在目录curl\winbuild\BUILD.WINDOWS.txt文件 ...

  9. About libcurl and cURL in PHP

    今天在学习php时遇到要调用curl 库函数对特定url字符串进行访问操作,需要自己写一个方法进行调用,之前在linux系统中也有用到cURL 命令行工具执行对相关资源的获取,在wiki上找到了如下的 ...

随机推荐

  1. ASP.NET MVC IOC依赖注入之Autofac系列(一)- MVC当中应用

    话不多说,直入主题看我们的解决方案结构: 分别对上面的工程进行简单的说明: 1.TianYa.DotNetShare.Model:为demo的实体层 2.TianYa.DotNetShare.Repo ...

  2. VMware虚拟机安装centos7

    镜像下载地址:http://www.linuxdown.net/ 在vmware上开始安装CentOS系统,点击菜单新建虚拟机,进入如下图步骤进行操作.   接着进行自定义硬盘操作   最后虚拟机就创 ...

  3. Python的range、enumerate和zip函数用法

    range函数可创建一个整数列表.如果需要知道当前元素在列表中的索引,推荐用enumerate代替range.zip函数用于同时遍历多个迭代器. 一.range 函数 range函数可创建一个整数列表 ...

  4. git submodule git 子模块管理相关操作

    Git 子模块操作相关的一些命令备忘: # 当使用git clone下来的工程中带有submodule时,初始的时候 submodule的内容并不会自动下载下来的,需执行如下命令: git submo ...

  5. Python—创建进程的三种方式

    方式一:os.fork() 子进程是从os.fork得到的值,然后赋值开始执行的.即子进程不执行os.fork,从得到的值开始执行. 父进程中fork之前的内容子进程同样会复制,但父子进程空间独立,f ...

  6. go语言设计模式之builder

    builder.go package builder type BuildProcess interface { SetWheels() BuildProcess SetSeats() BuildPr ...

  7. 解决问题:Red Hat Enterprise Linux 7 64 位 虚拟机安装后无法启动图形化

    原因: 1.系统在创建时,没有安装图形化 2.系统在安装后,有降低内存的操作,内存过低无法启动桌面,以及其他 就原因一进行图形化安装: 1.VMware挂载Red Hat Enterprise Lin ...

  8. wepy安装后提示Cannot read property 'addDeps'

    最近准备做一个微信小程序,以前一直用的小程序原始api做,但是这次准备用一个框架来做练习,当然在做之前需要比较一下现在小程序框架的优缺点. 经过认真挑选,选定wepy,Taro,uni-app,mpv ...

  9. subprocess模块(了解)

    目录 一.subprocess模块 一.subprocess模块 subprocess模块允许你去创建一个新的进程让其执行另外的程序,并与它进行通信,获取标准的输入.标准输出.标准错误以及返回码等.更 ...

  10. Java连载52-单例模式的缺点以及抽象类

    一.单例模式 1.单例模式的缺点:单例模式的类型没有子类,无法被继承. 例如:下面的例子,由于父类的构造方法是私有的,所以子类中的构造方法是无法创建的,因为它是引用父类的构造方法 package co ...