更新:Android HttpGet:リクエストを実行する前にチェックする必要がある例外は何ですか?
String xmlList = null;
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpGet request = new HttpGet(URL);
HttpResponse response = null;
response = httpClient.execute(request);
//HttpResponse httpResponse = httpClient.execute(request);
HttpEntity httpEntity = response.getEntity();
xmlList = EntityUtils.toString(httpEntity);
}
catch (MalformedURLException e) {
xmlList = "URL: is a malformed URL";
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
xmlList = "URL: UnsupportedEncodingException";
} catch (ClientProtocolException e) {
e.printStackTrace();
xmlList = "URL: ClientProtocolException";
} catch (SocketTimeoutException e) {
e.printStackTrace();
xmlList = "URL: SocketTimeoutException";
} catch (ConnectTimeoutException e) {
e.printStackTrace();
xmlList = "URL: ConnectTimeoutException";
} catch (IOException e) {
xmlList = "URL: IOException";
e.printStackTrace();
}
finally {
httpClient.getConnectionManager().shutdown();
}
// return XML
return xmlList;
更新終了
私は、ウェブサイトからデータを読み込み、私は例外が要求を実行する前に確認するべきであるされているかを知りたいアプリを構築していますか?
私は思っています例外:ここ
1) bad url
2) host not responding
3) time out
....
....
は私のコードです:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(SongsManager1.URL);
HttpResponse response = null;
response = httpClient.execute(request);
//HttpResponse httpResponse = httpClient.execute(request);
HttpEntity httpEntity = response.getEntity();
xmlList = EntityUtils.toString(httpEntity);
リクエストを行う前に、ホストが応答していないかどうかを確認します(タイムアウトとはどのように違いますか)。 –
あなたは正しいホストが応答しておらず、タイムアウトが同じであると思っていませんでした。 –