新闻中心
公司新闻

网站不会超时,安卓连接(localhost)本地超时

 public static String getJsonContent(String url_path) { 
        final String TAG = "HttpUtilsy";
        try {  
            URL url = new URL(url_path);  
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();  
            connection.setConnectTimeout(30000); // 请求超时时间3s 
            connection.setReadTimeout(30000);
            connection.setRequestMethod("GET");  
            connection.setDoInput(true);  
            int code = connection.getResponseCode(); // 返回状态码  
            Log.i(TAG,"ResposeCode="+code);
            if (code == 200) {  
                // 或得到输入流,此时流里面已经包含了服务端返回回来的JSON数据了,此时需要将这个流转换成字符串  
                return changeInputStream(connection.getInputStream());  
            }  
        catch (Exception e) {  
            // TODO: handle exception  
            Log.i(TAG,"HttpUrl异常:"+e);
        }  
        return "";  
    }  
 localhost,指的是本机,也就是安卓机器,这个必须用你电脑的ip地址。
你不会是在模拟器上跑的吧?
如果是模拟器是不能用127.0.0.1的
直用本地的IP:8080试试看,另外ping loalhost看一下是否正常。

上一篇:设计院管理网站不会超时,安卓连接(localhost)本地超时 下一篇:工程设计单位与甲方身份互换