Post方式调用webservice
调用的webservice地址:http://127.0.0.1:8080/AmsIFXjjsbt/services/UserGroupCatchServiceImpl?wsdl
方法简介: public int CA_UpdateForSame(String xmlString, String strTrustId)
调用实例见下图
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by Administrator on 2017/4/20.
*/
public class text3 {
public static void main(String[] args) throws Exception {
//服务的地址
URL wsUrl = new URL("http://127.0.0.1:8080/AmsIFXjjsbt/services/UserGroupCatchServiceImpl");
HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
OutputStream os = conn.getOutputStream();
//请求体
String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:impl=\"http://impl.service.unis.com\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <impl:CA_UpdateForSame>\n" +
" <impl:xmlString>" +
"<task>\n" +
"\t<org>\n" +
"\t\t<oper>del</oper>\n" +
"\t\t<id>34000003@gd.zg</id>\n" +
"\t\t<pid>34000002@gd.zg</pid>\n" +
"\t</org>\n" +
"</task>" +
"</impl:xmlString>\n" +
" <impl:strTrustId>111</impl:strTrustId>\n" +
" </impl:CA_UpdateForSame>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
os.write(soap.getBytes());
InputStream is = conn.getInputStream();
byte[] b = new byte[1024];
int len = 0;
String s = "";
while((len = is.read(b)) != -1){
String ss = new String(b,0,len,"UTF-8");
s += ss;
}
System.out.println(s);
is.close();
os.close();
conn.disconnect();
}
}
在请求体中
参数原始是这样的:
<task>
<org>
<oper>del</oper>
<id>34000003</id>
<pid>34000002</pid>
</org>
</task>
但发现这样访问不了webservice,所以将“<”转义为“<;*” 可以正常访问,原因不太知道,请知道的大神留言指导