use of android.net.http.AndroidHttpClient in project qksms by moezbhatti.
the class HttpUtils method createHttpClient.
private static AndroidHttpClient createHttpClient(Context context) {
String userAgent = MmsConfig.getUserAgent();
AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent, context);
HttpParams params = client.getParams();
HttpProtocolParams.setContentCharset(params, "UTF-8");
// set the socket timeout
int soTimeout = MmsConfig.getHttpSocketTimeout();
if (LOCAL_LOGV)
Log.d(TAG, "[HttpUtils] createHttpClient w/ socket timeout " + soTimeout + " ms, " + ", UA=" + userAgent);
HttpConnectionParams.setSoTimeout(params, soTimeout);
return client;
}
use of android.net.http.AndroidHttpClient in project robolectric by robolectric.
the class AndroidHttpClientTest method testNewInstanceWithContext.
@Test
public void testNewInstanceWithContext() throws Exception {
AndroidHttpClient client = AndroidHttpClient.newInstance("foo", RuntimeEnvironment.application);
assertThat(client).isNotNull();
}
use of android.net.http.AndroidHttpClient in project glitch-hq-android by tinyspeck.
the class ImageDownloader method downloadBitmap.
Bitmap downloadBitmap(String url) {
final int IO_BUFFER_SIZE = 4 * 1024;
try {
// AndroidHttpClient is not allowed to be used from the main thread
final HttpClient client = (mode == Mode.NO_ASYNC_TASK) ? new DefaultHttpClient() : AndroidHttpClient.newInstance("Android");
final HttpGet getRequest = new HttpGet(url);
try {
HttpResponse response = client.execute(getRequest);
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url);
return null;
}
final HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = null;
try {
inputStream = entity.getContent();
// Bug on slow connections, fixed in future release.
return BitmapFactory.decodeStream(new FlushedInputStream(inputStream));
} finally {
if (inputStream != null) {
inputStream.close();
}
entity.consumeContent();
}
}
} catch (IOException e) {
getRequest.abort();
Log.w(LOG_TAG, "I/O error while retrieving bitmap from " + url, e);
} catch (IllegalStateException e) {
getRequest.abort();
Log.w(LOG_TAG, "Incorrect URL: " + url);
} catch (Exception e) {
getRequest.abort();
Log.w(LOG_TAG, "Error while retrieving bitmap from " + url, e);
} finally {
if ((client instanceof AndroidHttpClient)) {
((AndroidHttpClient) client).close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of android.net.http.AndroidHttpClient in project android_frameworks_base by ParanoidAndroid.
the class GpsXtraDownloader method doDownload.
protected static byte[] doDownload(String url, boolean isProxySet, String proxyHost, int proxyPort) {
if (DEBUG)
Log.d(TAG, "Downloading XTRA data from " + url);
AndroidHttpClient client = null;
try {
client = AndroidHttpClient.newInstance("Android");
HttpUriRequest req = new HttpGet(url);
if (isProxySet) {
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
ConnRouteParams.setDefaultProxy(req.getParams(), proxy);
}
req.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
req.addHeader("x-wap-profile", "http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#");
HttpResponse response = client.execute(req);
StatusLine status = response.getStatusLine();
if (status.getStatusCode() != 200) {
// HTTP 200 is success.
if (DEBUG)
Log.d(TAG, "HTTP error: " + status.getReasonPhrase());
return null;
}
HttpEntity entity = response.getEntity();
byte[] body = null;
if (entity != null) {
try {
if (entity.getContentLength() > 0) {
body = new byte[(int) entity.getContentLength()];
DataInputStream dis = new DataInputStream(entity.getContent());
try {
dis.readFully(body);
} finally {
try {
dis.close();
} catch (IOException e) {
Log.e(TAG, "Unexpected IOException.", e);
}
}
}
} finally {
if (entity != null) {
entity.consumeContent();
}
}
}
return body;
} catch (Exception e) {
if (DEBUG)
Log.d(TAG, "error " + e);
} finally {
if (client != null) {
client.close();
}
}
return null;
}
use of android.net.http.AndroidHttpClient in project android_frameworks_base by ParanoidAndroid.
the class SslLoad method run.
public void run() {
boolean error = false;
while (true) {
synchronized (this) {
while (!running) {
try {
this.wait();
} catch (InterruptedException e) {
/* ignored */
}
}
}
AndroidHttpClient client = AndroidHttpClient.newInstance("Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101");
try {
// Cert. is for "www.google.com", not "google.com".
String url = error ? "https://google.com/" : "https://www.google.com";
client.execute(new HttpGet(url), new ResponseHandler<Void>() {
public Void handleResponse(HttpResponse response) {
/* ignore */
return null;
}
});
Log.i(TAG, "Request succeeded.");
} catch (IOException e) {
Log.w(TAG, "Request failed.", e);
}
client.close();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
/* ignored */
}
error = !error;
}
}
Aggregations