Http libcurl POST,删除Curl抛出的额外数据

Http libcurl POST,删除Curl抛出的额外数据,http,post,libcurl,Http,Post,Libcurl,有人知道从卷发柱上取下这个的方法吗 " method="post" name="form_reply" enctype="multipart/form-data"> 它被钉在邮件的邮递线上。即 POST /someurl/Topic/comment/replycreate/27537?sp=1**" method="post" name="form_reply" enctype="multipart/form-data">** HTTP/1.1 提前谢谢 好的,更多信息。。。

有人知道从卷发柱上取下这个的方法吗

" method="post" name="form_reply" enctype="multipart/form-data"> 
它被钉在邮件的邮递线上。即

POST /someurl/Topic/comment/replycreate/27537?sp=1**" method="post" name="form_reply" enctype="multipart/form-data">** HTTP/1.1 
提前谢谢

好的,更多信息。。。 顺便说一句:这是C,不是PHP



Curl将自动附加: “method=“post”name=“form\u reply”enctype=“多部分/表单数据”>

无论何时,只要你发布一篇文章,url就会包含参数,或者它认为传递的是参数

/someurl/Topic/comment/replycreate/27537*?sp=1*


因此,当您删除“?”问号和问号后的数据时,curl不再附加任何外观怪异的post参数…

我无法重现您的问题,URI完全按照顺序出现。我正在使用libcurl 7.22和以下代码构建请求:

BOOST_AUTO_TEST_CASE(case_http_session_libcurl)
{
  test_site::site test_site;
  std::string url = "http://localhost:";
  url += boost::lexical_cast<std::string>(test_site.start());
  url += "/post?some=1&data=2";
  char error[CURL_ERROR_SIZE];

  CURL *curl;
  int status=FALSE;
  curl = curl_easy_init();
  if(curl)
  {
    curl_slist* slist = NULL;
    slist = curl_slist_append(slist, "Expect:");
    slist = curl_slist_append(slist, "Some-Rubbish: here");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
    curl_easy_setopt(curl, CURLOPT_HEADER, 0);
    curl_easy_setopt(curl, CURLOPT_USERAGENT,  "testing goes here");
    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
    curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "");
    curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error[0]);
    curl_easy_setopt(curl, CURLOPT_ENCODING , "gzip");
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
    curl_easy_setopt(curl, CURLOPT_PROXY, "");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=being;posted=1");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_on_recv);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, 0);
    CURLcode result = curl_easy_perform(curl);
    curl_slist_free_all(slist);
    curl_easy_cleanup(curl);
    if(result == CURLE_OK)
    {
      status = TRUE;
    }
    else
    {
      printf("Error: [%d] - %s\n",result, error);
      status = FALSE;
    }
  }
}

您显然使用了错误的API,但这还不够。相关代码可能会有所帮助。“您显然使用了错误的API,但这还不够。相关代码可能会有所帮助Matthew Flaschen“请随时用正确的API启发我
BOOST_AUTO_TEST_CASE(case_http_session_libcurl)
{
  test_site::site test_site;
  std::string url = "http://localhost:";
  url += boost::lexical_cast<std::string>(test_site.start());
  url += "/post?some=1&data=2";
  char error[CURL_ERROR_SIZE];

  CURL *curl;
  int status=FALSE;
  curl = curl_easy_init();
  if(curl)
  {
    curl_slist* slist = NULL;
    slist = curl_slist_append(slist, "Expect:");
    slist = curl_slist_append(slist, "Some-Rubbish: here");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
    curl_easy_setopt(curl, CURLOPT_HEADER, 0);
    curl_easy_setopt(curl, CURLOPT_USERAGENT,  "testing goes here");
    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
    curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "");
    curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error[0]);
    curl_easy_setopt(curl, CURLOPT_ENCODING , "gzip");
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
    curl_easy_setopt(curl, CURLOPT_PROXY, "");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=being;posted=1");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_on_recv);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, 0);
    CURLcode result = curl_easy_perform(curl);
    curl_slist_free_all(slist);
    curl_easy_cleanup(curl);
    if(result == CURLE_OK)
    {
      status = TRUE;
    }
    else
    {
      printf("Error: [%d] - %s\n",result, error);
      status = FALSE;
    }
  }
}
POST /post?some=1&data=2 HTTP/1.1
User-Agent: testing goes here
Host: localhost:16385
Accept: */*
Accept-Encoding: gzip
Some-Rubbish: here
Content-Length: 19
Content-Type: application/x-www-form-urlencoded

data=being;posted=1