public static String getstr(String path) {
try {
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
if (conn.getResponseCode() == 200) {
InputStream inputStream = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
StringBuffer sf = new StringBuffer();
String str = "";
while ((str = br.readLine()) != null) {
sf.append(str);
}
String info = sf.toString();
Log.e("TAG", info);
return info;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
HttpURLConnection请求数据
最新推荐文章于 2022-10-11 15:48:40 发布