问题:用 android 4.4 写android访问http时,到connection.getResponseCode() 就不被执行,也不报错:但是抛出org.json.JSONException: End of input at character 0 of .异常:

连接代码:

public static String getJsonContent(String url_path){
    try {
        System.out.println("url_path---->>:"+url_path);
        URL url=new URL(url_path);
        HttpURLConnection connetion=(HttpURLConnection)url.openConnection();
        connetion.setConnectTimeout(3000);
        connetion.setRequestMethod("GET");
        connetion.setDoInput(true);
        System.out.println("connetion---->>:"+connetion);
        int code=connetion.getResponseCode();
        System.out.println("code---->>>:"+code);
        if (code==200){
            
            return changeInputStream(connetion.getInputStream());
        }else{
            System.out.println("---->>请求码不正确!!!");
            return "";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}
View Code

相关文章:

  • 2021-09-21
  • 2021-09-01
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2021-09-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-12-21
  • 2021-11-05
  • 2022-12-23
相关资源
相似解决方案