WebService通过Get方式调用第三方查询电话号码归属地

/**
 * 调用第三方服务查询电话号码归属地服务
 * @author dw
 * @Time 2018/5/16
 *
 */
public class MobileCodeService {

//1.get方式访问WebService
public void get(String mobileCode,String userID) throws IOException{
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();


}
public static void main(String[] args) throws IOException {


MobileCodeService ws = new MobileCodeService();
ws.get("1388983****", "");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值