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
);
connection.setReadTimeout(
30000
);
connection.setRequestMethod(
"GET"
);
connection.setDoInput(
true
);
int
code = connection.getResponseCode();
Log.i(TAG,
"ResposeCode="
+code);
if
(code ==
200
) {
return
changeInputStream(connection.getInputStream());
}
}
catch
(Exception e) {
Log.i(TAG,
"HttpUrl异常:"
+e);
}
return
""
;
}
localhost,指的是本机,也就是安卓机器,这个必须用你电脑的ip地址。
你不会是在模拟器上跑的吧?
如果是模拟器是不能用127.0.0.1的
直用本地的IP:8080试试看,另外ping loalhost看一下是否正常。
上一篇:网站不会超时,安卓连接(localhost)本地超时 下一篇:网站不会超时,安卓连接(localhost)本地超时