JAVA调用webService SOAP12

package com.ess.pos.info.impl;


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
  
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;


public class HttpWebService{
 
 public static void main(String[] args) throws HttpException, IOException {
          // TODO Auto-generated method stub
  
          String soapRequestData = ""
                  + "                   + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
                  + " xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
                  + " "
                  + " "
                //  + " "
                  + " QDZP001"
                  + " 2018-06-20"
           
                  //+ "
"
                  + "
" + "
"
                  + "
";
  
          System.out.println(soapRequestData);
  
          PostMethod postMethod = new PostMethod(
                  "http://******地址/WDService.asmx");
  
         // 然后把Soap请求数据添加到PostMethod中
         byte[] b = soapRequestData.getBytes("utf-8");
          InputStream is = new ByteArrayInputStream(b, 0, b.length);
          RequestEntity re = new InputStreamRequestEntity(is, b.length,
                 "application/soap+xml; charset=utf-8");
         postMethod.setRequestEntity(re);
         
          // 最后生成一个HttpClient对象,并发出postMethod请求
          HttpClient httpClient = new HttpClient();
          int statusCode = httpClient.executeMethod(postMethod);
          if(statusCode == 200) {
              System.out.println("调用成功!");
             String soapResponseData = postMethod.getResponseBodyAsString();
              System.out.println(soapResponseData);
              //截取出json数据
              int sub = soapResponseData.indexOf("");
              soapResponseData = soapResponseData.substring(sub).replace("", "");
              sub = soapResponseData.indexOf("
");
              soapResponseData = soapResponseData.substring(0, sub);
              System.out.println(soapResponseData);
              
              
          }
          else {
              System.out.println("调用失败!错误码:" + statusCode);
          }
  
      }
 

}

 

 

接口原页

 

WANDAService

 

单击此处,获取完整的操作列表。

GetTax

餐商逾期

测试

若要使用 HTTP POST 协议对操作进行测试,请单击“调用”按钮。

参数
sagncode:  
sDate:  
   

SOAP 1.1

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /WDService.asmx HTTP/1.1
Host: *
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.galasystec.net.cn/GetTax"



  
    
      string
      dateTime
    
  
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length



  
    
      string
    
  

SOAP 1.2

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /WDService.asmx HTTP/1.1
Host: *
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length



  
    
      string
      dateTime
    
  
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length



  
    
      string
    
  

HTTP GET

以下是 HTTP GET 请求和响应示例。所显示的占位符需替换为实际值。

GET /WDService.asmx/GetTax?sagncode=string&sDate=string HTTP/1.1
Host: *
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length


string

HTTP POST

以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。

POST /WDService.asmx/GetTax HTTP/1.1
Host: *
Content-Type: application/x-www-form-urlencoded
Content-Length: length

sagncode=string&sDate=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length


string

你可能感兴趣的:(java)