64,641
社区成员
发帖
与我相关
我的任务
分享
curl_global_init(CURL_GLOBAL_ALL);
CURL* hCurl = curl_easy_init();
if(hCurl != NULL)
{
curl_slist* pOptionList = NULL;
int filesize=0;
pOptionList = curl_slist_append(pOptionList, "Blog-X-User: username");
pOptionList = curl_slist_append(pOptionList, "Expect:");
curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, pOptionList);
curl_httppost* pFormPost = NULL;
curl_httppost* pLastElem = NULL;
//上传文件,指定本地文件完整路径
curl_formadd(&pFormPost, &pLastElem, CURLFORM_COPYNAME, "sendfile", CURLFORM_FILE, "D:\\a.png"/*, CURLFORM_CONTENTTYPE, "application/octet-stream"*/, CURLFORM_END);
curl_formadd(&pFormPost, &pLastElem, CURLFORM_COPYNAME, "filename", CURLFORM_COPYCONTENTS, "a.png", CURLFORM_END);
curl_formadd(&pFormPost,&pLastElem,CURLFORM_COPYNAME, "submit",CURLFORM_COPYCONTENTS, "send",
curl_easy_setopt(hCurl, CURLOPT_HTTPPOST, pFormPost);
curl_easy_setopt(hCurl, CURLOPT_URL, "http://XXXX.com/UploadFileServlet");
// curl_easy_setopt(hCurl, CURLOPT_HEADERFUNCTION,function);
// curl_easy_setopt(hCurl, CURLOPT_FOLLOWLOCATION,1);
// curl_easy_setopt(hCurl, CURLOPT_HEADERDATA, &filesize);
CURLcode res = curl_easy_perform(hCurl);
double t=0;
curl_easy_getinfo(hCurl,CURLINFO_SIZE_UPLOAD,&t);
if(res != CURLE_OK)
{
// std::cout << "Error" << std::endl;
}
curl_formfree(pFormPost);
curl_easy_cleanup(hCurl);
}
curl_global_cleanup();