}
public static HttpClient getHttpClient() {
DefaultHttpClient httpClient = new DefaultHttpClient();
final UserPreferences userPreferences = UserPreferences.getInstance();
if (userPreferences.isProxyEnabled()) {
// set up HTTP proxy
final String proxyHostname = userPreferences.getProxyHostname();
final int proxyPort = userPreferences.getProxyPort();
final HttpHost proxy = new HttpHost(proxyHostname, proxyPort);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
if (userPreferences.isProxyAuthenticationEnabled()) {
final AuthScope authScope = new AuthScope(proxyHostname, proxyPort);
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
userPreferences.getProxyUsername(), userPreferences.getProxyPassword());
httpClient.getCredentialsProvider().setCredentials(authScope, credentials);
}
}
return httpClient;