【基于crul库编写源码实现上传文件到http服务器】

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

基于crul库编写源码实现上传文件到http服务器

编译crul库(可以去我下载资源里面找)

tar xvf /home/lxr/lxr/crul/curl-7.73.0.tar.gz
cd curl-7.73.0/
./configure --prefix=$PWD/_install
//–prefix指定编译好工具和库存放的路径–host指定编译工具
make && make install

用postman生成代码

postman下载(可以去我上传资源里面下载
在这里插入图片描述

postman生成的代码

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
  res= curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
if(res!=CURLE_OK){
	printf("faile %d %d\n",__LINE__,res);
}
  res =curl_easy_setopt(curl, CURLOPT_URL, "http://172.20.10.18/httpserver/");
if(res!=CURLE_OK){
	printf("faile %d %d\n",__LINE__,res);
}  
  res =curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  	if(res!=CURLE_OK){
	printf("faile %d %d\n",__LINE__,res);
}
  res =curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
  	if(res!=CURLE_OK){
	printf("faile %d %d\n",__LINE__,res);
}
  struct curl_slist *headers = NULL;
  headers = curl_slist_append(headers, "Cookie: HFS_SID_=0QrlstPw5UAAAIDJIFTYPw");
  res =curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  	if(res!=CURLE_OK){
	printf("faile %d %d\n",__LINE__,res);
}
  curl_mime *mime;
  curl_mimepart *part;
  mime = curl_mime_init(curl);
  part = curl_mime_addpart(mime);
  res =curl_mime_name(part, "");
  	  	if(res!=CURLE_OK){
	printf("faile %d %d\n",__LINE__,res);
}
  res =curl_mime_filedata(part, "a.txt");
  	  	if(res!=CURLE_OK){
	printf("faile %d %d\n",__LINE__,res);
}
  res =curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
  	  	if(res!=CURLE_OK){
	printf("faile %d %d\n",__LINE__,res);
}
  res = curl_easy_perform(curl);
  	  	if(res!=CURLE_OK){
	printf("faile %d %d\n",__LINE__,res);
}
  curl_mime_free(mime);
}
curl_easy_cleanup(curl);

对应的http服务器的设置

可以参考我之前那章<<移植crul到富瀚6630平台上传文件到http服务器>>

_msnap_send_to_httpserver函数有http通过json发送jpeg文件、以及上传ftp服务器、发邮件的实例

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: 服务器