use of org.apache.http.impl.client.DefaultHttpClient in project android_frameworks_base by ParanoidAndroid.
the class FsUtils method getHttpClient.
private static HttpClient getHttpClient() {
if (sHttpClient == null) {
HttpParams params = new BasicHttpParams();
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), ForwarderManager.HTTP_PORT));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), ForwarderManager.HTTPS_PORT));
ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);
sHttpClient = new DefaultHttpClient(connectionManager, params);
HttpConnectionParams.setSoTimeout(sHttpClient.getParams(), HTTP_TIMEOUT_MS);
HttpConnectionParams.setConnectionTimeout(sHttpClient.getParams(), HTTP_TIMEOUT_MS);
}
return sHttpClient;
}
use of org.apache.http.impl.client.DefaultHttpClient in project Anki-Android by Ramblurr.
the class HttpFetcher method fetchThroughHttp.
public static String fetchThroughHttp(String address, String encoding) {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(address);
HttpResponse response = httpClient.execute(httpGet, localContext);
if (!response.getStatusLine().toString().contains("OK")) {
return "FAILED";
}
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName(encoding)));
StringBuilder stringBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
return stringBuilder.toString();
} catch (Exception e) {
return "FAILED with exception: " + e.getMessage();
}
}
use of org.apache.http.impl.client.DefaultHttpClient in project Anki-Android by Ramblurr.
the class HttpUtility method postReport.
public static Boolean postReport(String url, List<NameValuePair> values) {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
try {
httpPost.setEntity(new UrlEncodedFormEntity(values));
HttpResponse response = httpClient.execute(httpPost);
switch(response.getStatusLine().getStatusCode()) {
case 200:
Log.e(AnkiDroidApp.TAG, String.format("feedback report posted to %s", url));
return true;
default:
Log.e(AnkiDroidApp.TAG, String.format("feedback report posted to %s message", url));
Log.e(AnkiDroidApp.TAG, String.format("%d: %s", response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
break;
}
} catch (ClientProtocolException ex) {
Log.e(AnkiDroidApp.TAG, ex.toString());
} catch (IOException ex) {
Log.e(AnkiDroidApp.TAG, ex.toString());
}
return false;
}
use of org.apache.http.impl.client.DefaultHttpClient in project android_frameworks_base by ParanoidAndroid.
the class CookiesTest method testCookiesAreNotLogged.
/**
* Test that we don't log potentially sensitive cookie values.
* http://b/3095990
*/
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
// enqueue an HTTP response with a cookie that will be rejected
server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
server.play();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Logger logger = Logger.getLogger("org.apache.http");
StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
logger.addHandler(handler);
try {
HttpClient client = new DefaultHttpClient();
client.execute(new HttpGet(server.getUrl("/").toURI()));
handler.close();
String log = out.toString("UTF-8");
assertTrue(log, log.contains("password"));
assertTrue(log, log.contains("fake.domain"));
assertFalse(log, log.contains("secret"));
} finally {
logger.removeHandler(handler);
}
}
use of org.apache.http.impl.client.DefaultHttpClient in project android_frameworks_base by ParanoidAndroid.
the class DefaultHttpClientTest method testServerClosesOutput.
private void testServerClosesOutput(SocketPolicy socketPolicy) throws Exception {
server.enqueue(new MockResponse().setBody("This connection won't pool properly").setSocketPolicy(socketPolicy));
server.enqueue(new MockResponse().setBody("This comes after a busted connection"));
server.play();
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse a = client.execute(new HttpGet(server.getUrl("/a").toURI()));
assertEquals("This connection won't pool properly", contentToString(a));
assertEquals(0, server.takeRequest().getSequenceNumber());
HttpResponse b = client.execute(new HttpGet(server.getUrl("/b").toURI()));
assertEquals("This comes after a busted connection", contentToString(b));
// sequence number 0 means the HTTP socket connection was not reused
assertEquals(0, server.takeRequest().getSequenceNumber());
}
Aggregations