Use AndroidHttpClient.

This commit is contained in:
Michael Kuhn 2012-04-30 13:24:25 +02:00 committed by Andrew Dolgov
parent cf3357d49b
commit dd95973d2d
2 changed files with 19 additions and 24 deletions

View File

@ -111,18 +111,10 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE
if (m_transportDebugging) Log.d(TAG, ">>> (" + requestStr + ") " + m_api); if (m_transportDebugging) Log.d(TAG, ">>> (" + requestStr + ") " + m_api);
DefaultHttpClient client; AndroidHttpClient client = AndroidHttpClient.newInstance("Tiny Tiny RSS");
if (m_trustAny) { if (m_trustAny) {
SchemeRegistry schemeRegistry = new SchemeRegistry(); client.getConnectionManager().getSchemeRegistry().register(new Scheme("https", new EasySSLSocketFactory(), 443));
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
HttpParams httpParams = new BasicHttpParams();
client = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
} else {
client = new DefaultHttpClient();
} }
try { try {
@ -141,6 +133,8 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE
return null; return null;
} }
HttpContext context = null;
String httpLogin = m_prefs.getString("http_login", "").trim(); String httpLogin = m_prefs.getString("http_login", "").trim();
String httpPassword = m_prefs.getString("http_password", "").trim(); String httpPassword = m_prefs.getString("http_password", "").trim();
@ -157,14 +151,18 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE
} }
HttpHost targetHost = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol()); HttpHost targetHost = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol());
CredentialsProvider cp = new BasicCredentialsProvider();
context = new BasicHttpContext();
client.getCredentialsProvider().setCredentials( cp.setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()), new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials(httpLogin, httpPassword)); new UsernamePasswordCredentials(httpLogin, httpPassword));
context.setAttribute(ClientContext.CREDS_PROVIDER, cp);
} }
httpPost.setEntity(new StringEntity(requestStr, "utf-8")); httpPost.setEntity(new StringEntity(requestStr, "utf-8"));
HttpResponse execute = client.execute(httpPost); HttpResponse execute = client.execute(httpPost, context);
m_httpStatusCode = execute.getStatusLine().getStatusCode(); m_httpStatusCode = execute.getStatusLine().getStatusCode();

View File

@ -487,21 +487,14 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
} }
protected void downloadFile(String fetchUrl, String outputFile) { protected void downloadFile(String fetchUrl, String outputFile) {
DefaultHttpClient client; AndroidHttpClient client = AndroidHttpClient.newInstance("Tiny Tiny RSS");
if (m_prefs.getBoolean("ssl_trust_any", false)) { if (m_prefs.getBoolean("ssl_trust_any", false)) {
SchemeRegistry schemeRegistry = new SchemeRegistry(); client.getConnectionManager().getSchemeRegistry().register(new Scheme("https", new EasySSLSocketFactory(), 443));
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
HttpParams httpParams = new BasicHttpParams();
client = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
} else {
client = new DefaultHttpClient();
} }
HttpGet httpGet = new HttpGet(fetchUrl); HttpGet httpGet = new HttpGet(fetchUrl);
HttpContext context = null;
String httpLogin = m_prefs.getString("http_login", ""); String httpLogin = m_prefs.getString("http_login", "");
String httpPassword = m_prefs.getString("http_password", ""); String httpPassword = m_prefs.getString("http_password", "");
@ -517,15 +510,19 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
} }
HttpHost targetHost = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol()); HttpHost targetHost = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol());
CredentialsProvider cp = new BasicCredentialsProvider();
context = new BasicHttpContext();
client.getCredentialsProvider().setCredentials( cp.setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()), new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials(httpLogin, httpPassword)); new UsernamePasswordCredentials(httpLogin, httpPassword));
context.setAttribute(ClientContext.CREDS_PROVIDER, cp);
} }
try { try {
HttpResponse execute = client.execute(httpGet); HttpResponse execute = client.execute(httpGet, context);
InputStream content = execute.getEntity().getContent(); InputStream content = execute.getEntity().getContent();