XML-RPC failing to respond to POST requests via cURL in PHP

  • Unknown's avatar

    Hi,

    Starting today (or at least it’s only been noticed today), we’ve been getting some strange messages back from XML-RPC. We’ve been successfully using wp.getPosts via XML-RPC for over a year now, and suddenly (with no changes to our code), it’s just stopped working.

    We’re using cURL in PHP to do this:

    $ch = curl_init(“http://sunseekerblogbook.wordpress.com/xmlrpc.php”);
    curl_setopt_array($ch, [
    CURLOPT_HEADER => false,
    CURLOPT_HTTPHEADER => [
    “Content-Type: text/xml”
    ],
    CURLOPT_POSTFIELDS => xmlrpc_encode_request(“wp.getPosts”, [
    1,
    WP_USERNAME,
    WP_PASSWORD,
    [
    “number” => 15
    ]
    ]),
    CURLOPT_RETURNTRANSFER => true
    ]);
    $ret = curl_exec($ch);

    $method = null;
    $content[“data”] = xmlrpc_decode_request($ret, $method, “UTF-8”);

    The curl_exec function fails with error #52: Empty reply from server. I’ve tried the same code snippet on a couple of different servers, and the same problem arose every time.

    Has there been a change to XML-RPC that I’m not adhering to or is there anything else that someone can shed some light on?

    Cheers,
    Warren

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

  • Unknown's avatar

    Just to add, it looks like this might have something to do with PHP’s implementation of cURL. The following works absolutely fine:

    $output = [];
    exec(“curl -d ”<?xml version=’1.0′ encoding=’UTF-8′?><methodCall><methodName>wp.getPosts</methodName><params><param><value><int>1</int></value></param><param><value><string>” . WP_USERNAME . “</string></value></param><param><value><string>” . WP_PASSWORD . “</string></value></param><param><value><struct><member><name>number</name><value><int>15</int></value></member></struct></value></param></params></methodCall>” sunseekerblogbook.wordpress.com/xmlrpc.php”, $output);

    $content[“data”] = xmlrpc_decode(implode(“”, $output), “UTF-8”);

  • Unknown's avatar

    Never mind – managed to fix it. 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 3.9.2) now requires a user agent for XML-RPC request, though this hasn’t been documented anywhere that I can find.

  • Unknown's avatar

    This is the WordPress.COM support forum. You cannot get support for any WordPress.ORG software here at all. You need to post to the WordPress.ORG support forum for help with that site because it is not hosted by WordPress.COM.

    WordPress.com and WordPress.org are completely separate and have different logins http://support.wordpress.com/com-vs-org/

    If you don’t have a username account at WordPress.ORG click http://wordpress.org/support/ and register one on the top right hand corner of the page that opens, so you can post to the support forums there and receive advice from WordPress.ORG bloggers.

  • Unknown's avatar

    Thank you timethief, but I think you’ve misread my post. I am asking for WordPress.COM support. The site IS hosted on WordPress.COM, and I’ve resolved this issue myself (as you can see in my response just before your post), and have mentioned how this only affects WordPress.COM blogs.

  • Unknown's avatar

    Okay then – sorry. I’ll tag this thread for a Staff follow-up. Please subscribe to the thread so you are notified when they respond and please be patient while waiting.

  • Unknown's avatar

    Hi there,

    Thanks for letting us know! We don’t tend to document a whole lot of these types of changes as they can and do change quite frequently. In fact most of our coding information is not documented for that reason. Is there a particular page which you were referring to that you think this change should be included on?

  • Unknown's avatar

    Hi,

    Thanks for getting back to me. To be honest, I’ve had a quick flick through and can’t think of any good place!

    The XML-RPC Specification does require a User-Agent header to be set, so it’s natural that this should be the case when interacting with WordPress’s implementation, and anyone wishing to interact with XML-RPC themselves should probably read that documentation first, as it is covered there.

    Most people will probably end up using one of the clients available, and unfortunately it seems that few are sending this now vital header. I know these libraries you reference are most probably third-party, but I’ve issued a pull request for the PHP library at least.

    Warren

  • Unknown's avatar

    I’ll put this in front of the group of us who handles documentation and see if it’s something that the group thinks we should make a change on and document publicly.

    Thanks for writing back on it though and for bringing it to our attention. I really appreciate it!

  • The topic ‘XML-RPC failing to respond to POST requests via cURL in PHP’ is closed to new replies.