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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
+ " xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
+ " <soap12:Body>"
+ " <GetTax xmlns=\"http://www.galasystec.net.cn/\">"
// + " <GetAPACShippingPackageRequest>"
+ " <sagncode>QDZP001</sagncode>"
+ " <sDate>2018-06-20</sDate>"
//+ " </GetAPACShippingPackageRequest>"
+ " </GetTax>" + "</soap12:Body>"
+ " </soap12:Envelope>";
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("<GetTaxResult>");
soapResponseData = soapResponseData.substring(sub).replace("<GetTaxResult>", "");
sub = soapResponseData.indexOf("</GetTaxResult>");
soapResponseData = soapResponseData.substring(0, sub);
System.out.println(soapResponseData);
}
else {
System.out.println("调用失败!错误码:" + statusCode);
}
}
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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
+ " xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
+ " <soap12:Body>"
+ " <GetTax xmlns=\"http://www.galasystec.net.cn/\">"
// + " <GetAPACShippingPackageRequest>"
+ " <sagncode>QDZP001</sagncode>"
+ " <sDate>2018-06-20</sDate>"
//+ " </GetAPACShippingPackageRequest>"
+ " </GetTax>" + "</soap12:Body>"
+ " </soap12:Envelope>";
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("<GetTaxResult>");
soapResponseData = soapResponseData.substring(sub).replace("<GetTaxResult>", "");
sub = soapResponseData.indexOf("</GetTaxResult>");
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" <?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> <GetTax xmlns="http://www.galasystec.net.cn/"> <sagncode>string</sagncode> <sDate>dateTime</sDate> </GetTax> </soap:Body> </soap:Envelope>
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?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> <GetTaxResponse xmlns="http://www.galasystec.net.cn/"> <GetTaxResult>string</GetTaxResult> </GetTaxResponse> </soap:Body> </soap:Envelope>
SOAP 1.2
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。
POST /WDService.asmx HTTP/1.1 Host: * Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GetTax xmlns="http://www.galasystec.net.cn/"> <sagncode>string</sagncode> <sDate>dateTime</sDate> </GetTax> </soap12:Body> </soap12:Envelope>
HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GetTaxResponse xmlns="http://www.galasystec.net.cn/"> <GetTaxResult>string</GetTaxResult> </GetTaxResponse> </soap12:Body> </soap12:Envelope>
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 <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://www.galasystec.net.cn/">string</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 <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://www.galasystec.net.cn/">string</string>