我无法使用curl在c语言中的wordpress页面上发表评论。我尝试了formadd,但没有再次发生。

<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">


我应该如何发布?

最佳答案

这是一个简单的curl示例。如果要求使用严格的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
}

10-08 03:37