AndroidプログラムのWebサービスからデータを取得する方法(以下)があります。Android2.2で正常に動作します。ただし、4.xでは、「ErrorRequestingAPI」というメッセージとともに例外がスローされます。私のコードでどの部分が例外を引き起こしているのか、そしてなぜ4.xでのみ例外が発生しているのかわからない誰かが私にいくつかのポインターを与えることができますか?
public static synchronized String performHTTPRequest(HttpUriRequest request)
throws ApiException, ParseException, IOException {
HttpClientWrapper cli=new HttpClientWrapper();
HttpClient client;
try {
client=cli.getClient();
HttpResponse response = client.execute(request);
// Check if server response is valid
StatusLine status = response.getStatusLine() ;
if (status.getStatusCode() != HTTP_STATUS_OK) {
throw new ApiException("Invalid response from server: " + status.toString());
}
return EntityUtils.toString(response.getEntity());
} catch (MalformedURLException e) {
throw new Error(e);
} catch (Exception cnrce) {
throw new ApiException("Error requesting API:");
}
}