webservice-实现手机号码归属地的查询

package com.webservice;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * get方法获取手机归属地
 * @author zhunode
 *
 */
public class mobilephone {
	public void getPhone(String mobileCode,String userID) throws Exception{
        URL url =new URL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode="+mobileCode+"&userID="+userID);
        HttpURLConnection counc = (HttpURLConnection)url.openConnection();
        counc.setRequestMethod("GET");
        if(counc.getResponseCode()==HttpURLConnection.HTTP_OK) {
        	InputStream is = counc.getInputStream();
        	ByteArrayOutputStream boas = new ByteArrayOutputStream();
        	byte[] buffer = new byte[1024];
        	int len;
        	 if((len=is.read(buffer)) != -1){
                 boas.write(buffer, 0, len);
             }
             System.out.println("GET请求获取的数据:\n"+boas.toString());  
             boas.close();
             is.close();
             
        }
	}
	public void postPhoneInfo() {
		
	}
	
	public static void main(String[] args) throws Exception {
		mobilephone mobile = new mobilephone();
		mobile.getPhone("18150850130", "");
	}
}

输出结果为:

GET请求获取的数据:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://WebXml.com.cn/">18150850130:福建 宁德 福建电信CDMA卡</string>

原文章链接:webservice-实现手机号码归属地的查询

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值