zoukankan      html  css  js  c++  java
  • java 获取手机归属地,引起net.UnknownHostException错误

    这个问题是请求,重定向了,跟入源码。修改了地址,变成302

                    Connection connect = Jsoup.connect(url);
    	        connect.header("Host", "http://info.bet007.com");
    	        connect.header("User-Agent", "  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0");
    	        connect.header("Accept", "  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    	        connect.header("Accept-Language", "zh-cn,zh;q=0.5");
    	        connect.header("Accept-Charset", "  GB2312,utf-8;q=0.7,*;q=0.7");
    	        connect.header("Connection", "keep-alive");
    			
    	        Document doc = connect.get();
    

      就可以获取到手机归属地了

    	public static String[] getPhoneAddressAndCompanyStrs(String phone){
    		if(phone.length()<=0)
    			return null;
    		String url = "http://www.ip138.com:8080/search.asp?action=mobile&mobile=%s";
    		url = String.format(url, phone);
    		
    		String[] strs=new String[2];
    		try {
    			Connection connect = Jsoup.connect(url);
    	        connect.header("Host", "http://info.bet007.com");
    	        connect.header("User-Agent", "  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0");
    	        connect.header("Accept", "  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    	        connect.header("Accept-Language", "zh-cn,zh;q=0.5");
    	        connect.header("Accept-Charset", "  GB2312,utf-8;q=0.7,*;q=0.7");
    	        connect.header("Connection", "keep-alive");
    			
    	        Document doc = connect.get();
    			
    			Elements els = doc.getElementsByClass("tdc2");
    			int elsSize = els.size();
    			if(elsSize == 2) {
    				strs[0]=els.get(1).text();
    			}else if(elsSize > 2) {
    				strs[0]=els.get(1).text();
    				strs[1]=els.get(2).text();
    			}
    			return strs;
    		} catch (IOException e) {
    			
    			e.printStackTrace();
    			return null;
    		}
    	}
    

      

  • 相关阅读:
    js当地天气调用
    js 3D旋转效果
    js 格林威治时间转正常格式并兼容ios
    vue中使用百度地图,悬浮窗搜索功能
    js 百度地图定位
    高德地图坐标与百度地图坐标相互转换
    js高德地图手机定位
    数据循环处理重组2
    数据循环处理重组1
    百度地图搜索框在弹框中不显示
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/11024957.html
Copyright © 2011-2022 走看看