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>

 

posted @ 2020-08-27 17:42  wq9  阅读(352)  评论(0)    收藏  举报