2010-09-07 67 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