67,513
社区成员
发帖
与我相关
我的任务
分享
{
String BOUNDARY = UUID.randomUUID().toString(); // 边界标识 随机生成
String RequestURL = serverUrl + "scandir.php?path=" + path;
System.out.println(RequestURL);
try {
URL url = new URL(RequestURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(TIME_OUT);
conn.setConnectTimeout(TIME_OUT);
conn.setDoInput(true); // 允许输入流
conn.setDoOutput(true); // 允许输出流
conn.setUseCaches(false); // post不允许使用缓存
conn.setRequestProperty("Charset", CHARSET); // 设置编码
// conn.setRequestProperty("connection", "keep-alive");
// conn.setRequestProperty("Content-Type", CONTENT_TYPE +
// ";boundary=" + BOUNDARY);
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String readLine = "";
StringBuilder sb = new StringBuilder();
while ((readLine = br.readLine()) != null) {
sb.append(readLine);
}
/**
* 获取响应码 200=成功 当响应成功,获取响应的流
*/
int res = conn.getResponseCode();
System.out.println(conn.getResponseMessage());
System.out.println(sb.toString());
System.out.println(res);
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}