问题:用 android 4.4 写android访问http时,到connection.getResponseCode() 就不被执行,也不报错。如下面红色字体:
public static String getJsonContent(String url_path ,String encode){
String jsonString = "";
try {
URL url = new URL(url_path);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setConnectTimeout(3000);
connection.setRequestMethod("GET");
connection.setDoInput(true); //从服务器获得数据
int responseCode = connection.getResponseCode();
if (200 == responseCode) {
jsonString = changeInputStream(connection.getInputStream(),encode);
}
} catch (Exception e) {
// TODO: handle exception
}
//
return jsonString;
}
private static String changeInputStream(InputStream inputStream , String encode) throws IOException {
// TODO Auto-generated method stub
String