关于HttpURLConnection :Connection timed out: connect 问题~!!!
private String getWebData(String strurl) { try { URL url = new URL(strurl); // 打开连接,此处只是创建一个实例,并没有真正的连接 HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setConnectTimeout(30000); httpCon.setReadTimeout(30000); httpCon.setDoOutput(true);//打开写入属性 httpCon.setRequestMethod("POST");//设置提交方法 httpCon.connect();//建立连接 InputStream inputStream = httpCon.getInputStream(); InputStreamReader inputReader = new InputStreamReader(inputStream,"utf-8"); BufferedReader bufferReader = new BufferedReader(inputReader); StringBuffer sb = new StringBuffer(); String inputLine = null; while ((inputLine = bufferReader.readLine()) != null) { sb.append(inputLine+"\n"); } bufferReader.close(); inputReader.close(); inputStream.close(); httpCon.disconnect(); System.out.println(sb.toString().trim()); return sb.toString(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("======================================================="); return null; }