【发布时间】:2016-09-24 04:19:11
【问题描述】:
我在 c++ 中使用 libCurl 向我的服务器发出 xml 文件的 POST 请求。帖子有效,我在我的服务器上收到了 xml。然而,xml 周围还有一个奇怪的页眉和页脚:
------------------------------b6966127f870Content-Disposition: form-data; name="myName"; filename="myFile.xml"Content-Type: application/xml<CORRECT XML FILE HERE>------------------------------b6966127f870--
这个页眉/页脚是什么?
我可以摆脱它吗?还是我应该只解析它?
curl 会添加这些吗?
这是我为发布 xml 文件所做的相关 curl 调用。
void CurlUtils::postFileToURL(const char* const inFile,
const char* const urlString)
{
// Setup
CURL* const curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
// Post
struct curl_httppost* post = NULL;
struct curl_httppost* last = NULL;
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "myName",
CURLFORM_FILE, inFile,
CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_URL, urlString);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
curl_easy_perform(curl);
// Cleanup ...
}
【问题讨论】: