私のアプリケーションはサーブレットにリクエストを頻繁に送信していましたが、昨日からUnknownHostException Exceptionが発生し始めました。
マニフェスト ファイルにインターネットへのアクセス許可を追加しました。私のサーブレットは PC ブラウザで正常に動作しています。
Android でサーブレットを呼び出すための私のコードは次のとおりです。
String url = "http://sampark.iiit.ac.in:8080/VTSServlets/CurrentTripInfo?mobilenum=##########&lat=10&long=10"
String response = getResponse(url);
public static String getResponse(final String url)
{
final StringBuilder builder = new StringBuilder();
final HttpClient client = new DefaultHttpClient();
System.out.println("URL :: " + url);
final HttpGet httpGet = new HttpGet(url);
try {
final HttpResponse response = client.execute(httpGet);
final StatusLine statusLine = response.getStatusLine();
final int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
final HttpEntity entity = response.getEntity();
final InputStream content = entity.getContent();
final BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
builder.append("Not 200");
}
} catch (final ClientProtocolException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
}
return builder.toString();
}
}
すべての要件を確認しましたが、どのように UnknownHost Exception が突然発生するのかわかりませんか? Android モバイルでアプリケーションをテストしています。