zoukankan      html  css  js  c++  java
  • JAVA : Using Metaweblog API

    JAVA : Using Metaweblog API | CodingX

    JAVA : Using Metaweblog API

    I was interested in this API since a long time but I didn't take time to write a post on it !
    The purpose of this article is to show how to post on a blog without using the common web-interface, and build your own publish-system.
    The metaweblog API is based on the xmlrpc library distributed by Apache, it's opensource and really easy to work with :)
    Tanks to indiwiz/ for the topic !

    public class Blog {
    private String login ; 
    private String password ;

    public boolean post(String title ,String link ,String description){
    boolean retStatus = true;
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    try {
    config.setServerURL(new URL("http://localhost/mw"));
    } catch (MalformedURLException e) {
    System.out.println("Exception catch :: server URL");
    retStatus = false ; 
    }
    XmlRpcClient client = new XmlRpcClient();
    client.setConfig(config);


    Map m = new HashMap();
    m.put("title", "Hello World ");
    m.put("link", "http://www.perdu.com/");
    m.put("description", "Message de test!");


    Object[] params = new Object[]{"default", login, password, m, true};


    try {
    String ret = (String) client.execute("metaWeblog.newPost", params);
    } catch (XmlRpcException e) {
    System.out.println("Exception catch, unable to execute statement");
    retStatus = false ; 
    }
    return retStatus;
    }


    public String getLogin() {
    return login;
    }


    public void setLogin(String login) {
    this.login = login;
    }


    public void setPassword(String password) {
    this.password = password;
    }
    }
    Required dependencies : (http://apache.belnet.be//ws/xmlrpc/)
     
  • 相关阅读:
    code review
    自我封闭
    怎么验证?
    DRUPAL点滴
    CRLF CSRF XSS
    各种element/format 在manage display 下的选项
    html list <==> unformatted list
    ctrl + d 在phpstorm 和 eclipse 中的不同含义
    常量和变量的区别
    JSON和php里的数据序列化
  • 原文地址:https://www.cnblogs.com/lexus/p/2787236.html
Copyright © 2011-2022 走看看