Xmlrpcclient 如何使用XmlRpc客户端自定义xml请求
我遇到了这个问题:我试图使用Apache的XmlRpc客户端发送一个自定义xml请求。我得到了一个XmlRpcClient实例,它包含一些名为“execute”的方法,如下所示:Xmlrpcclient 如何使用XmlRpc客户端自定义xml请求,xmlrpcclient,Xmlrpcclient,我遇到了这个问题:我试图使用Apache的XmlRpc客户端发送一个自定义xml请求。我得到了一个XmlRpcClient实例,它包含一些名为“execute”的方法,如下所示: public class RPCClient { public static void main(String[] args) { try { XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
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>
POST/SOAP HTTP/1.1
内容类型:text/xml
用户代理:Apache XML RPC 3.1.3(Sun HTTP传输)
缓存控制:没有缓存
Pragma:没有缓存
主持人:***********
接受:text/html、image/gif、image/jpeg、*;q=.2,*/*;q=.2
连接:保持活力
内容长度:200
A_方法
4.
3.
简而言之,这个客户机没有“execute”方法来接收简单字符串或类似的内容。因此,我的问题是如何发送自定义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>
string1
string2
弦3
123
提前谢谢 用于与协议通信。您试图发送的消息是另一种协议(请参见问题)
要发送此消息,您可以使用常规HTTP客户端以纯文本(如果它只是一条简单消息)的形式发送,也可以使用完整的SOAP库。我知道这是一个相当老的问题,但这是“XmlRpcClient”中排名最靠前的问题。