我遇到了这个问题:我正在尝试使用 Apache 的 XmlRpc-Client 发送自定义 xml 请求。我有一个 XmlRpcClient 的实例,它包含一些名为“execute”的方法,如下所示:
public class RPCClient {
public static void main(String[] args) {
try {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://localhost:8888/SOAP"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Object[] params = new Object[]{new Integer(4), new Integer(3)};
String myResponse = (String) client.execute("A_Method", params);
System.out.println("Suc " + myResponse);
} catch (Exception e) {
System.out.println("Err " + e.getMessage());
}
}
}
它正在发送这个:
POST /SOAP HTTP/1.1
Content-Type: text/xml
User-Agent: Apache XML RPC 3.1.3 (Sun HTTP Transport)
Cache-Control: no-cache
Pragma: no-cache
Host: ***********
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 200
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>A_Method</methodName>
<params>
<param>
<value>
<i4>4</i4>
</value>
</param>
<param>
<value>3</value>
</param>
</params>
</methodCall>
简而言之,这个客户端没有“执行”方法来接收简单的字符串或类似的东西。所以我的问题是如何发送我的自定义 xml,应该如下所示:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:rp="http://www.abcdef.com/GH"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Header> </soapenv:Header>
<soapenv:Body>
<rp:A_Methodsoapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<package xsi:type="xsd:string">string1</package>
<event xsi:type="xsd:string">string2</event>
<fields xsi:type="rp:ArrayOfKeyValuePair" soapenc:arrayType="rp:KeyValuePair[]">
<item xsi:type="rp:KeyValuePair">
<key xsi:type="xsd:string">string3</key>
<value xsi:type="xsd:string">123</value>
</item>
</fields>
</rp:A_Method>
</soapenv:Body></soapenv:Envelope>
提前致谢!