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);
请发表评论