3
回答
android 请求数据问题
【腾讯云】学生服务器套餐10元/月 >>>   

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

----------



/**
* 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;
}


<无标签>
举报
smarthjx636
发帖于2年前 3回/163阅
顶部