返回顶部

收藏

Apache XMLRPC 的例子

更多

java代码

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:8080/xmlrpc"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Object[] params = new Object[]{new Integer(33), new Integer(9)};
Integer result = (Integer) client.execute("Calculator.add", params);

标签:rpc,XmlRpcClient,XmlRpcClientConfigImpl,Apache,XML

收藏

0人收藏

支持

0

反对

0

评论

  • 我调用的wordpress的上传接口 XmlRpcClientConfigImpl config=new XmlRpcClientConfigImpl(); try { config.setServerURL(new URL(serverUrl)); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } XmlRpcClient client=new XmlRpcClient(); client.setConfig(config); if(attachList!=null&&attachList.size()>0){ Integer count = 0; for(Attach attach:attachList){ File orig = new File(request.getSession().getServletContext().getRealPath("/")+filePath+attach.getResourcesName()); Map origData = new HashMap(); origData.put("name", attach.getFileName()); origData.put("type", "image/jpeg"); try { origData.put("bits", FileUtils.readFileToByteArray(orig)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } origData.put("overwrite", Boolean.TRUE); Object[] origParams = new Object[]{new Integer(1),"admin","admin",origData}; //远程方法调用 try { Map resultMap = (Map)client.execute("metaWeblog.newMediaObject", origParams); rt = ((String)resultMap.get("url")).toString(); if(rt!=null){ count++; } if(count==attachList.size()){ result = 1 ; } } catch (XmlRpcException e) { e.getMessage(); // TODO Auto-generated catch block e.printStackTrace(); } } } 能上传成功,但在execute时抛异常: org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse servers response: 不允许有匹配 "[xX][mM][lL]" 的处理指令目标。

    回复   |   yuans2769 发表于 2017-05-08 15:34:11

发表评论