[resolved] XML-RPC and cURLS (10 posts)

  1. ale.sasha
    Posted 5 years ago #

    Since I’m not able to edit php.ini file on my hosting service, I need to use cURL without the xmlrpc_encode_request() PHP function, and I’m trying to pass the XML request whithout using such function.
    So, I've activated XML-RPC from WP Administration Panel, I've activated cURL from my hosting service administration page, and I’m using the following code:


    function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords=”,$encoding=’UTF-8′) {
    $title = htmlentities($title,ENT_NOQUOTES,$encoding);
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
    $ch = curl_init();
    $curlStr="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><methodCall><methodName>metaWeblog.newPost</methodName><params>".
    "<param><value><string><title> TITOLO </title><category> CATEGORIA </category> BODY </string></value></param>".

    curl_setopt($ch, CURLOPT_URL, $rpcurl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    $results = curl_exec($ch);
    return $results;

    but it seems to be wrong: I get the following error:
    Warning: curl_error(): supplied argument is not a valid cURL handle resource in …

    How can I fix It, please?
    Thank you,

  2. Joseph Scott
    Posted 5 years ago #

    Check to see if you got a valid resource back from curl_init().

    Also XML-RPC is a lot easier if you just use one of the PHP libraries for it. WordPress uses IXR, works well.

  3. ale.sasha
    Posted 5 years ago #

    curl_init give me a valid resource, so it is ok. The problem is on the XML string I pass to curl_exec throug $ch, but I don't know how pass it correctly.

    I'd really like to use a PHP library for XML-RPC, but, which one can be used whithout editing php.ini?

    Thank you,

  4. ale.sasha
    Posted 5 years ago #

    This is the XML I pass to the curl_exec();

    <?xml version="1.0" encoding="iso-8859-1"?>
    <title> TITOLO </title>
    <description> DESC </description>

    Is it right for WordPress?
    Thank you,

  5. Joseph Scott
    Posted 5 years ago #

    You can use the IXR library without touching the php.ini file.

  6. ale.sasha
    Posted 5 years ago #

    Ok, thank you.
    With IXR Lib, how should I pass parameters? Is there some example written for wordpress posting through xml-rpc?

  7. Joseph Scott
    Posted 5 years ago #

    A simple XML-RPC client example is available in IXR docs - http://scripts.incutio.com/xmlrpc/basic-client-construction.php

  8. attuk
    Posted 5 years ago #

    Hi Scott,
    Is there a way to detect duplicate posts or pages when using IXR xmlrpc to post ?

  9. Joseph Scott
    Posted 5 years ago #

    If I understand your question correctly, no, the XML-RPC API doesn't try to detect duplicate posts. If you tell it that what you sent is a new post, it will treat it as a new post.

  10. attuk
    Posted 5 years ago #

    Thanks Scott, I am trying to make sure that I don't post the same page/post more than once. WP happily creates a new URL for the same content when I try to post with IXR/XMLRPC.

Topic Closed

This topic has been closed to new replies.

About this Topic