Home » Wordpress » Post data in wordpress from java using xmlrpc

Post data in wordpress from java using xmlrpc

Posted by: admin November 30, 2017 Leave a comment

Questions:

I am trying to post data in wordpress using this code but I am getting token null

In place of sXmlRpcURL I have used http://wordpress.com/ and http://sUsername.wordpress.com/ also but both the cases its generating token null.

    String sXmlRpcURL= arg[0];
    String sUsername = arg[1];
    String sPassword = arg[2];

    // Hard-coded blog_ID
    int blog_ID = 1;

    // XML-RPC method
    String sXmlRpcMethod = "blogger.newPost";
    // XML-RPC method ver 2                      

// sXmlRpcMethod = “metaWeblog.newPost”; // I have used this also

    // We'll hard-code our blog content for now as well
    String sTitle = "HI........";
    String sContent = "Hello XML-RPC World!";

    // Create our content struct
    HashMap hmContent = new HashMap();
    hmContent.put("title", sTitle);
    hmContent.put("description", sContent);

    // You can specify whether or not you want the blog published immediately
    boolean bPublish = true;

    // Try block
    try {
        // Create the XML-RPC client
        XmlRpcClient client = new XmlRpcClient(sXmlRpcURL,true);

        // Make our method call
        Object token = client.invoke( sXmlRpcMethod, new Object[] { new Integer( blog_ID ), sUsername, sPassword, hmContent, new Boolean( bPublish ) } );

        // The return is a String containing the postID
        System.out.println("Posted : " + (String) token);
    } // Catch exceptions
    catch (Exception e) {
    }

please help me.

Answers:

I have got the solution you want to use –

http://sUsername.wordpress.com/xmlrpc.php?

for sXmlRpcURL.
Now it working well-