浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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/)
 
posted on 2012-11-25 09:33  lexus  阅读(293)  评论(0编辑  收藏  举报