80,351
社区成员
发帖
与我相关
我的任务
分享
public static String getJsonContent(String url_path) {
final String TAG = "HttpUtilsy";
try {
URL url = new URL(url_path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(30000); // 请求超时时间3s
connection.setReadTimeout(30000);
connection.setRequestMethod("GET");
connection.setDoInput(true);
int code = connection.getResponseCode(); // 返回状态码
Log.i(TAG,"ResposeCode="+code);
if (code == 200) {
// 或得到输入流,此时流里面已经包含了服务端返回回来的JSON数据了,此时需要将这个流转换成字符串
return changeInputStream(connection.getInputStream());
}
} catch (Exception e) {
// TODO: handle exception
Log.i(TAG,"HttpUrl异常:"+e);
}
return "";
}