java如何调用php接口,并获取值

URL url = new URL("php接口路径");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setConnectTimeout(10000);
    conn.setRequestMethod("GET");
    conn.setDoInput(true);
    conn.setDoOutput(true);
 
 
    // 输出返回结果
    InputStream input = conn.getInputStream();
    int resLen =0;
    byte[] res = new byte[1024];
    StringBuilder sb=new StringBuilder();
    while((resLen=input.read(res))!=-1){
      sb.append(new String(res, 0, resLen));
    }
     
    String jsonStr=sb.toString();

 System.out.println(jsonStr);

posted @ 2019-07-08 17:29  fdbnf  阅读(3038)  评论(0编辑  收藏  举报