java对接.net大佬的webservice(x-www-frorm-urlencoded,string xmlns="http://tempuri.org/)
(1)引入maven包
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
(2)代码实现
try { String postURL = "http://118.24.*.*:8080/Dar_TWS_Service.asmx/GetFromStation"; PostMethod postMethod = null; postMethod = new PostMethod(postURL) ; postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") ; //参数设置,需要注意的就是里边不能传NULL,要传空字符串 NameValuePair[] data = { new NameValuePair("_ArgStr","*") }; postMethod.setRequestBody(data); org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient(); int response = httpClient.executeMethod(postMethod); // 执行POST方法 String result = postMethod.getResponseBodyAsString() ; System.out.println(response); System.out.println(result); } catch (Exception e) { // logger.info("请求异常"+e.getMessage(),e); throw new RuntimeException(e.getMessage()); }
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetPatrolPro xmlns="http://tempuri.org/">
<Majorname>string</Majorname>
</GetPatrolPro>
</soap:Body>
</soap:Envelope>

个人学习笔记,记录日常学习,便于查阅及加深,仅为方便个人使用。

浙公网安备 33010602011771号