Wordpress XMLRPC returns empty but successfully

I am trying to post in WordPress using curl via PHP. I am sending using XMLRPC, the default built in Wordpress.

The posting was successful with the code below, but nothing is returned. I need to know some information about the message, for example, the URL - I can do this if I have a "message identifier" which, by looking at the xmlrpc.php file, should return. Below is my post code:

    function post($username, $password, $title, $content, $url, $category=array(), $keywords='', $type='Wordpress')
{
    $encoding = 'UTF-8';

    $title = htmlentities($title,ENT_NOQUOTES,$encoding);
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);

    $reqparams = array(
        'title'=>$title,
        'description'=>$content,
        'mt_allow_comments'=>0,  // 1 to allow comments
        'mt_allow_pings'=>0,  // 1 to allow trackbacks
        'post_type'=>'post',
        'mt_keywords'=>$keywords,
        'categories'=>$category
    );
    $params = array(0,$username,$password,$reqparams,true);
    $request = xmlrpc_encode_request('metaWeblog.newPost',$params);
    $ch = curl_init();

    $fp = fopen('/home/*/public_html/file.txt', 'w+');

    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_STDERR, $fp);
    $results = curl_exec($ch);
    echo '<pre>'.print_r($results, true).'</pre>';
    curl_close($ch);
    return $results;

}

The line echo '<pre>'.print_r($re...shows only <pre></pre>. I have detailed curl output to a file, please find it below (I highlighted the url):

* About to connect() to www.*******.com port 80 (#0)
*   Trying 87.106.55.179... * connected
* Connected to www.*******.com (87.*.*.179) port 80 (#0)
> POST /xmlrpc.php HTTP/1.1
Host: www.*******.com
Accept: */*
Content-Length: 1445
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

< HTTP/1.1 100 Continue
* Operation timed out after 1000 milliseconds with 0 bytes received
* Closing connection #0

, , . , , . , , , ?

+3
2

. : curl_setopt($ch, CURLOPT_TIMEOUT, 1); 10: curl_setopt($ch, CURLOPT_TIMEOUT, 10);, XML-, post.

, , -.

+4

($ results) xml... , - ( , xml ). xmlrpc_decode XML XML. .

, ,

$results = curl_exec($ch);
$results = xmlrpc_decode($results);
echo '<pre>'.print_r($results, true).'</pre>';
-2

Source: https://habr.com/ru/post/1781857/


All Articles