try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("https://www.example.com");
HttpResponse response = client.execute(request);
// ...
} catch (IOException e) {
e.printStackTrace();
}
class CustomExceptionHandler implements ResponseHandler<String> {
@Override
public String handleResponse(HttpResponse response) throws IOException {
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() >= 300) {
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
HttpEntity entity = response.getEntity();
if (entity != null) {
return EntityUtils.toString(entity);
} else {
return null;
}
}
}
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("https://www.example.com");
String response = client.execute(request, new CustomExceptionHandler());
// ...
} catch (IOException e) {
e.printStackTrace();
}
HttpParams params = new BasicHttpParams();
HttpClient client = new DefaultHttpClient(params);
HttpParams params = new BasicHttpParams();
HttpClient client = new DefaultHttpClient(params);