Can't Get posts using XML-RPC

  • Unknown's avatar

    Hi there,

    I am using XML-RPC to get posts from my wordpress blog. I have a php file hosted on an external server to wordpress.com that has the following code:

    require_once("IXR_Library.php"); 
    
    // Create the client object
    $client = new IXR_Client('http://wodnet.wordpress.com/xmlrpc.php');
    $client->debug = true; //
    $username = "myusername";
    $password = "mypassword"; 
    
    $params = array(0,$username,$password,10); 
    
    if (!$client->query('metaWeblog.getRecentPosts', $params)) {
      die('Something went wrong - '.$client->getErrorCode().' : '.$client->getErrorMessage());
    }

    I get the following error:
    “Something went wrong – -32300 : transport error – HTTP status code was not 200”

    This exact code works on a different wordpress blog not hosted with wordpress.com. Is there something in wordpress.com that I need to set in order for this to work? I have the basic free edition right now, do I need to upgrade to have this work? Any help would be awesome!

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar

    Hello there,

    I’m not an XML-RPC expert, but found a not so old thread that may be relevant.It may have to do with indicating a user agent in your code.
    I realize that the other thread is about publishing, and you simply want to get posts, but I guess it may not hurt to investigate this user agent detail. :)

    Looking at the headers sent by cURL, the only differences were that the cURL command line uses Content-Type: application/x-www-form-urlencoded and that the user agent was set to User-Agent: curl/7.30.0.

    The choice of content type didn’t affect it, but setting a user agent sorted it! It seems WordPress.com (but not self-hosted WordPress.org sites running the latest v3.9.2) now requires a user agent for XML-RPC requests, though this hasn’t been documented anywhere that I can find.

    This is quoted from August 2014 on stackoverflow, so I imagine it still applies now.

    Let us know if it works out or not!

  • Unknown's avatar

    Hi guaiava,

    Thanks for the reply. I tried changing the user agent and the content type but still get the same error.
    The header with the changes is:

    POST /xmlrpc.php HTTP/1.0
    Host: wodnet.wordpress.com
    Content-Type:  application/x-www-form-urlencoded
    User-Agent: curl/7.30.0
    Content-Length: 377

    and the original header was:

    POST /xmlrpc.php HTTP/1.0
    Host: wodnet.wordpress.com
    Content-Type: text/xml
    User-Agent: The Incutio XML-RPC PHP Library
    Content-Length: 377

    It seems like the wordpress.com server is refusing the connection for some reason…?

  • Unknown's avatar

    I dug a little more in the forum, and it may be network related… but well, the thread has been tagged for the staff’s attention, so let see what they say!

  • Unknown's avatar

    Hi there!

    I’m not super familiar with PHP, but I do know we don’t allow users direct access to our servers through FTP or the like. So, this could be the issue you’re running into. Can you tell me more about what you’re trying to do?

  • The topic ‘Can't Get posts using XML-RPC’ is closed to new replies.