2010-12-16 15 views
0

任何人都知道一種方法可以從Curl文章中刪除此...?libcurl POST,刪除由Curl引發的額外數據

" method="post" name="form_reply" enctype="multipart/form-data"> 

它被固定在郵件的POST行上。即...

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

在此先感謝...!

OK,更多信息... BTW:這是C,而不是PHP


CURL *curl; 
CURLcode result; 
char errorBuffer[CURL_ERROR_SIZE]; 
int status=FALSE; 
BufHandle *Bufhandle = CreateBufHandle(BUFSIZE); 
memset(&errorBuffer,0x0,sizeof(errorBuffer)); 
curl = curl_easy_init(); 
if(curl) 
{ 
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, GetPtrToSlist(S)); 
    curl_easy_setopt(curl, CURLOPT_HEADER, 0); 
    curl_easy_setopt(curl, CURLOPT_USERAGENT, GetParameterByName(S, "useragent")); 
    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, GetParameterByName(S, "cookiefile")); 
    curl_easy_setopt(curl, CURLOPT_COOKIEJAR, GetParameterByName(S, "cookiefile")); 
    curl_easy_setopt(curl, CURLOPT_URL, url); 
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &errorBuffer); 
    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); 
    //curl_easy_setopt(curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_easy_setopt(curl, CURLOPT_POST, 1); 
    //curl_easy_setopt(curl, CURLOPT_USERPWD, buf); 
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer); 
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)Bufhandle); 
    result = curl_easy_perform(curl); 
    curl_slist_free_all(GetPtrToSlist(S)); 
    curl_easy_cleanup(curl); 
    if(result == CURLE_OK) 
    { 
    status = TRUE; 
    } 
    else 
    { 
    printf("Error: [%d] - %s\n",result, errorBuffer); 
    status = FALSE; 
    } 
} 
+0

你顯然使用API​​錯誤,但是這是沒有足夠的信息相關的代碼可能。 – 2010-12-16 03:03:17

+0

「你顯然使用API​​錯誤,但是這個信息不夠。相關的代碼可能會有幫助。 - Matthew Flaschen「請隨時使用CORRECT API給我啓發 – chinasailor 2010-12-16 04:27:40

回答

0

捲曲會自動追加: 「方法=」 郵報 「NAME = 」form_reply「 ENCTYPE =」的multipart/form-data的「>

任何時候你做一個職位和URL包括參數,或它認爲正在傳遞的參數是什麼。

/someurl /主題/評論/ replycreate/27537 * ?sp = 1 *

因此,當您刪除'?'問號和問號後面的數據,curl不再附加任何奇怪的看帖子參數...

0

我無法重現你的問題,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; 
    } 
    } 
} 

,並通過HTTP服務器接收到的請求是:

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