SSK
SSK

Reputation: 285

How to input Post Data to xmlrpc.php?

We have xmlrpc.php with one CMS, I am trying to give POST input to xmlrpc.php.

<methodCall>
    <methodName>openads.view</methodName>
    <params>
      <param>
        <value>
            <struct>
                <member>
                    <name>Ronald</name>
                    <value>25</value>
                </member>
        <member>
      </member>
      <member>
        <name>cookies</name>
        <value>
        <array>123123</array>
      </value>
      </member>
      </struct>
      </value>
      </param>
      <param><value><string>height</string></value></param>
      <param><value><int>1</int></value></param>
      <param><value><string>hjbj3h3</string></value></param>
      <param><value><string>kj3n434kjn</string></value></param>
      <param><value><boolean>1</boolean></value></param>
      <param><value><array><data>342</data></array></value></param>
    </params>
    </methodCall>

I am trying to give above XML POST input to the XMLRPC.php , by using PHP but execution getting failed. How i can input all this inputs using php ? If you have any example you can suggest me.

Upvotes: 1

Views: 1129

Answers (1)

Jens A. Koch
Jens A. Koch

Reputation: 41756

Try to send the xml as POST request with cURL. The data arrives as $_POST['xml']. Read the docs of your xmlrpc.php library, if this is accepted, else adjust it.

    $url = 'http://somewhere/xmlrpc.php';        

    $xmlString = '<methodCall>....'; // your xml

    $post = array(                   // POST
       'xml' => $xmlString; 
    );

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);    // <--- POST array
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $output = curl_exec($ch);

    if(curl_errno($ch)) {
        print curl_error($ch);
    } else {
        curl_close($ch);
    }

    echo $output;

Upvotes: 2

Related Questions