测试调用XXX.asmx类型接口

来源:互联网 发布:cad2016简体中文版mac 编辑:程序博客网 时间:2024/06/02 01:34

使用类型XXX.asmx该类型的借口查询的
掉用火车票借口查询火车时刻表

package com.Threadtest;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.methods.GetMethod;import org.apache.commons.httpclient.util.HttpURLConnection;public class ServiceDemo {    public static void main(String[] args) {        ServiceDemo2  a = new ServiceDemo2();        a.request();    }    public void request (){        String mobileCode = "K1276";        HttpClient client = new HttpClient();          GetMethod getMethod= new GetMethod  ("http://ws.webxml.com.cn/WebServices/TrainTimeWebService.asmx/getStationAndTimeDataSetByLikeTrainCode?TrainCode=" + mobileCode + "&UserID=");          //http://ws.webxml.com.cn/WebServices/TrainTimeWebService.asmx/getStationAndTimeDataSetByLikeTrainCode?TrainCode=K1276&UserID=//执行,得到消息码          try {            Thread.sleep(1000);            int  code = client.executeMethod(getMethod);            System.out.println("消息码:"+code);             if (code==HttpURLConnection.HTTP_OK) {                  String  result = getMethod.getResponseBodyAsString();                System.out.println(result);              }         } catch (Exception e) {            e.printStackTrace();        }    }}
原创粉丝点击