• Resolved alesasha

    (@alesasha)


    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:

    <backticks>

    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/></value></param>”.
    “<param><value><string/></value></param>”.
    “<param><value><string>”.$username.”</string></value></param>”.
    “<param><value><string>”.$password.”</string></value></param>”.
    “<param><value><string><title> TITOLO </title><category> CATEGORIA </category> BODY </string></value></param>”.
    “<param><value><int>1</int></value></param>”.
    “</params></methodCall>”;

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

    </backticks>
    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,
    Ale

Viewing 9 replies - 1 through 9 (of 9 total)
  • 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.

    Thread Starter alesasha

    (@alesasha)

    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,
    Ale

    Thread Starter alesasha

    (@alesasha)

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

    <?xml version=”1.0″ encoding=”iso-8859-1″?>
    <methodCall>
    <methodName>metaWeblog.newPost</methodName>
    <params>
    <param><value><int>0</int></value></param>
    <param><value><string>myusr</string></value></param>
    <param><value><string>mypwd</string></value></param>
    <param><value><string>
    <title> TITOLO </title>
    <description> DESC </description>
    BODY
    </string></value></param>
    <param><value><int>1</int></value></param>
    </params>
    </methodCall>

    Is it right for WordPress?
    Thank you,
    Ale

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

    Thread Starter alesasha

    (@alesasha)

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

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

    attuk

    (@attuk)

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

    Joseph Scott

    (@josephscott)

    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.

    attuk

    (@attuk)

    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.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘XML-RPC and cURLS’ is closed to new replies.