WordPress xmlprc not working in https

Recently, I have updated my site using an SSL and all URIs are now “https://”.

My site is developed with Symfony 2 and mixing a WordPress installation inside Symfony 2 web/wordpress directory.

Read More

All regular access is fine. Only one question:

In my Symfony 2, there is this code snippet:

private function getRecentPosts($num = 4)
{
    require_once 'wordpress/wp-includes/class-IXR.php';

    $user      = '11111';
    $pwd       = '22222';

    $host='https://www.rsywx.net';
    $script='/wordpress/xmlrpc.php';
    $port=443;

    $client = new IXR_Client($host, $script, $port);

    $params = array(0, $user, $pwd, $num);
    $client->query('metaWeblog.getRecentPosts', $params);

    $wp = $client->getResponse();

    return $wp;
}

When my site is not wrapped with https, the above code works fine. But now it is under https, the above code is not working. If I dump the $client variable after the query function call, it gives an error like:

+error: IXR_Error {#256 ▼
    +code: -32300
    +message: "transport error - could not open socket"

Any hints? Do I need to tweak my WP?

Related posts

Leave a Reply

2 comments

  1. The problem was on the file wp-includes/class-IXR.php, it doesn’t work with HTTPS, you must use also class-wp-http-ixr-client.php . And don’t forget to include the configuration file wp-load.php.

    The code snippet will be:

    private function getRecentPosts($num = 4) 
    {
        include 'wordpress/wp-load.php';
        require_once ABSPATH . WPINC . 'wordpress/wp-includes/class-IXR.php';
        require_once ABSPATH . WPINC . 'wordpress/wp-includes/class-wp-http-ixr-client.php';
    
    
        $user      = '11111';
        $pwd       = '22222';
    
        //Deprecated
        /*
        $host='https://www.rsywx.net';
        $script='/wordpress/xmlrpc.php';
        $port=443;
        $client = new IXR_Client($host, $script, $port);
        */
        $client = new WP_HTTP_IXR_CLIENT('https://www.rsywx.net/wordpress/xmlrpc.php');
    
        $params = array(0, $user, $pwd, $num);
        $client->query('metaWeblog.getRecentPosts', $params);
    
        $wp = $client->getResponse();
    
        return $wp;
    }
    
  2. I just avoided using XMLRPC at all to solve this.

    In my Symfony 2 application, I just used a 2nd database to directly access the underlying wordpress database. It is a hack but it resolves my issue for the time being.