91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

C版本的HTTP,可以上傳多個文件,可以向服務器發送json字串.自己工程中正在使用.因為也是是從網上找到的,做了一定修改,所以共享出來.

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?
#include?
#include?
#include?“gh_http.h“
#include?“tcpclient.h“

static?int?http_post_file(tcpclient?*pclient?const?char?*page
?????const?char*?message_json?const?char?*filepath
?????char?**response)
{

????//check?if?the?file?is?valid?or?not
????struct?stat?stat_buf;
????if(lstat(filepath&stat_buf)<0){
????????GH_LOG_INFO(“lstat?%s?fail“?filepath);
????????return?-1;
????}
????if(!S_ISREG(stat_buf.st_mode)){
????????GH_LOG_INFO(“%s?is?not?a?regular?file!“filepath);
????????return??-1;
????}
?
????char?*filename;
????filename=strrchr((char*)filepath‘/‘);
????if(filename==NULL)
????{
?
????}
????filename+=1;
????if(filename>=filepath+strlen(filepath)){
????????//‘/‘?is?the?last?character
????????GH_LOG_INFO(“%s?is?not?a?correct?file!“filepath);
????????return??-1;
????}
?
????//GH_LOG_INFO(“filepath=%sfilename=%s“filepathfilename);
?
????char?content_type[4096];
????memset(content_type?0?4096);
?
????char?post[512]host[256];
????char?*lpbuf*ptmp;
????int?len=0;
?
????lpbuf?=?NULL;
????const?char?*header2=“User-Agent:?Is?Http?1.1\r\nCache-Control:?no-cache\r\nAccept:?*/*\r\n“;
?
????sprintf(post“POST?%s?HTTP/1.1\r\n“page);
????sprintf(host“HOST:?%s:%d\r\n“pclient->remote_ippclient->remote_port);
????strcpy(content_typepost);
????strcat(content_typehost);
?
?
????char?*boundary?=?(char?*)“-----------------------8d9ab1c50066a“;
?
????strcat(content_type?“Content-Type:?multipart/form-data;?boundary=“);
????strcat(content_type?boundary);
????strcat(content_type?“\r\n“);

????//--Construct?request?data?{filePath?file}
????char?content_before[8192];
????memset(content_before?0?8192);

????//GH_LOG_TEXT(message_json);
????????//附加數據。
????strcat(content_before?“--“);
????strcat(content_before?boundary);
????strcat(content_before?“\r\n“);
????strcat(content_before?“Content-Disposition:?form-data;?name=\“consite_message\“\r\n\r\n“);
????strcat(content_before?message_json);
????strcat(content_before?“\r\n“);

????strcat(content_before?“--“);
????strcat(content_before?boundary);
????strcat(content_before?“\r\n“);
????strcat(content_before?“Content-Disposition:?attachment;?name=\“file\“;?filename=\““);
????strcat(content_before?filename);
????strcat(content_before?“\“\r\n“);
????strcat(content_before?“Content-Type:?image/jpeg\r\n\r\n“);

????char?content_end[2048];
????memset(content_end?0?2048);
????strcat(content_end?“\r\n“);
????strcat(content_end?“--“);
????strcat(content_end?boundary);
????strcat(content_end?“--\r\n“);

????int?max_cont_len=5*1024*1024;
????char?content[max_cont_len];
????int?fd;
????fd=open(filepathO_RDONLY0666);
????if(!fd){
????????GH_LOG_INFO(“fail?to?open?file?:?%s“filepath);
????????return?-1;
????}
????len=read(fdcontentmax_cont_len);
????close(fd);

????char?*lenstr;
????lenstr?=?(char*)GH_MEM_MALLOC(256);
????sprintf(lenstr?“%d“?(int)(strlen(content_before)+len+strlen(content_en

評論

共有 條評論