String urlStr = "nana.com/nana/api/v1"
HttpURLConnection conn = null;
BufferedReader rd = null;
StringBuilder sb = null;
try {
URL url = new URL(urlStr);
conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() != 200) {
throw new IOException(conn.getResponseMessage());
}
else {
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
}
} catch (IOException i) {
i.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
这是我的连接,我真的不想使用 apache。如果服务器无法访问,我希望我的应用程序显示一些错误消息,但它会崩溃,我有点没有想法。