java实现电话号码归属地的查询
/**
*MobileUtils类的实现
*/
import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;/** * Created by xiaoxin111 on 2016/3/21. */public class MobileUtils { public static String query(String tel) { String str=""; try{ //访问网络 URL url=new URL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/" + "getMobileCodeInfo?mobileCode="+tel+"&userID="); HttpURLConnection con =(HttpURLConnection)url.openConnection(); con.setRequestMethod("GET"); con.setConnectTimeout(9000); con.setDoInput(true); con.connect(); int code=con.getResponseCode(); StringBuffer sb=new StringBuffer(); if (code == 200) { InputStream is= con.getInputStream(); byte [] bs=new byte[1024]; int len=0; while((len=is.read(bs))!=-1){ sb.append(new String(bs,0,len)); } } con.disconnect(
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
