在我的android项目中,我遇到了问题。(即)有时没有从服务器获得响应。我使用 Urlconnection 类连接到服务器。
URL myURL = new URL(url);
URLConnection conn = myURL.openConnection();
InputStream is = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line = "";
StringBuilder sb = new StringBuilder();
while ((line = in.readLine()) != null) {
sb.append(line + "\n");
Log.v("response is .....",
"=================Response===================="
+ sb.toString());
}
in.close();