首页 > Web开发 > 详细

webservice学习教程(三)--

时间:2019-04-19 11:59:29      阅读:136      评论:0      收藏:0      [点我收藏+]

快速入门

首先,我们来尝试一下调用别人写好的webService

来体验一把:我们访问http://www.webxml.com.cn/zh_cn/index.aspx

 进入到里边

技术分享图片

 

 

技术分享图片

当我们输入一个号码,它就能够查询出我们的手机位置信息:

技术分享图片

我们现在要做的就是将这个服务让我们自己写的应用程序中也可以调用,那怎么做呢???

http-get方式访问webservice

技术分享图片

 
public void get(String mobileCode ,String userID ) throws Exception{
        URL url=new URL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode="+mobileCode+
                "&userID="+userID);
        HttpURLConnection conn=(HttpURLConnection) url.openConnection();
        conn.setConnectTimeout(5000);
        conn.setRequestMethod("GET");
        if(conn.getResponseCode()==HttpURLConnection.HTTP_OK){ //结果码=200
            InputStream is=conn.getInputStream();
            //内存流 ,  
            ByteArrayOutputStream boas=new ByteArrayOutputStream();
            byte[] buffer=new byte[1024];
            int len=-1;
            while((len=is.read(buffer))!=-1){
                boas.write(buffer, 0, len);
            }
            System.out.println("GET请求获取的数据:"+boas.toString());
            boas.close();
            is.close();
        }
    }

 


 

webservice学习教程(三)--

原文:https://www.cnblogs.com/xiaohuizhenyoucai/p/10734640.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!