2010-09-07 70 views
0

我不能發表評論,在C中使用curl wordpress頁。我試過formadd,但它沒有再次發生。發表評論到wordpress在c

<input id="author" name="author" type="text" value="" size="30" aria-required="true"> 
<input id="email" name="email" type="text" value="" size="30" aria-required="true"> 
<input id="url" name="url" type="text" value="" size="30"> 
<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea> 
<input name="submit" type="submit" id="submit" value="Yorum Yaz"> 

我該怎麼發帖?

+1

到目前爲止您能向我們展示您的C嗎? – 2010-09-07 09:51:45

回答

1

這是一個簡單的捲曲示例。如果需求是針對嚴格C而不是C++,請將下面的std :: string更改爲char數組。

CURL *curl; 
CURLcode res; 
std::string postParams; 

//Set parameters 
postParams.clear(); 
postParams.append("&parameter1="); 
postParams.append("data"); 
postParams.append("&parameter2="); 
postParams.append("more data"); 

//Initialize curl 
curl = curl_easy_init(); 

if(curl){ 
    //Set site 
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.yoursite.com"); 

    //Use post, set parameters 
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *)postParams.c_str()); 

    //Perform the session 
    res = curl_easy_perform(curl); 

    //Cleanup the session 
    curl_easy_cleanup(curl); 
} 

if(res == 0){ 
    //Success 
} 
else{ 
    //Failure 
} 
+0

你應該解釋參數是如何工作的。這對初學者來說並不直觀。此外,OP還爲您提供了參數的名稱,因此如果您在答案中使用這些參數將會很好。 – 2010-09-07 11:09:12