android 请求数据问题

smarthjx636 发布于 2016/10/27 11:25
阅读 198
收藏 0

请问这样请求数据,有错误么,为啥感觉略慢

----------



/**
* get 请求

* @param url
*            如果错误返回 "";
*/
public static String doget(String url) {
long l = System.currentTimeMillis();
String tmp = "";
HttpURLConnection httpUrl = null;
try {
URL url2 = new URL(url);
httpUrl = (HttpURLConnection) url2.openConnection();
httpUrl.connect();
httpUrl.setReadTimeout(5 * 1000);
httpUrl.setConnectTimeout(5 * 1000);
BufferedReader reader = new BufferedReader(new InputStreamReader(
httpUrl.getInputStream()));
StringBuffer stringBuffer = new StringBuffer();
;
String lines = "";
while ((lines = reader.readLine()) != null) {
stringBuffer.append(lines);
}
tmp = stringBuffer.toString();


} catch (Exception e) {
Logi.e(e);
}
if (httpUrl != null) {
httpUrl.disconnect();
}
Logi.i("result " + (System.currentTimeMillis() - l) + "ms >>>" + url+">> "
+ tmp);
return tmp;
}


加载中
0
银杏卡卡
银杏卡卡
android内置了httpclient组件,你可以用它试试
0
飞越围墙
飞越围墙

引用来自“BoXuan”的评论

android内置了httpclient组件,你可以用它试试

android 6.0 Apache HTTP Client Removal

银杏卡卡
银杏卡卡
这个还真没注意,误导楼主了,抱歉
0
smarthjx636
smarthjx636
这里需要 关流不
返回顶部
顶部