使用libCurl POST添加未知的页眉和页脚

Using libCurl to POST adds unknown header and footer

本文关键字:未知 libCurl POST 添加 使用      更新时间:2023-10-16

我使用libCurl在c++中使一个xml文件的POST请求到我的服务器。后工作,我收到我的服务器上的xml。然而,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 ...
}

您使用的是CURLOPT_HTTPPOST,它使多部分表单post到服务器。多部分formpost是一系列带有MIME样式分隔符的部分,每个部分都有一组标题,正如您在这里看到的。

如果你想要一个普通的POST,没有多部分的东西,使用CURLOPT_POSTFIELDS或设置一个读回调,使用CURLOPT_POST