@Test public void testNewInstanceWithContext() throws Exception { AndroidHttpClient client = AndroidHttpClient.newInstance("foo", RuntimeEnvironment.application); assertThat(client).isNotNull(); }
@Test public void testExecute() throws IOException { AndroidHttpClient client = AndroidHttpClient.newInstance("foo"); FakeHttp.addPendingHttpResponse(200, "foo"); HttpResponse resp = client.execute(new HttpGet("/foo")); assertThat(resp.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(CharStreams.toString(new InputStreamReader(resp.getEntity().getContent(), UTF_8))) .isEqualTo("foo"); } }
@Test public void testNewInstance() throws Exception { AndroidHttpClient client = AndroidHttpClient.newInstance("foo"); assertThat(client).isNotNull(); }
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link android.content.Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
public AndroidApacheClient() { super(AndroidHttpClient.newInstance("Retrofit")); } }
public BaseHttpClient(final String userAgent) { this.userAgent = userAgent; this.client = AndroidHttpClient.newInstance(userAgent); this.auth = new BasicAuthenticator(); }
protected String executeDeletePost(MultipartEntity entity) { AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); try { HttpPost request = new HttpPost(url);
private String[] readUrl(String urlString) { InputStream in = null; BufferedReader reader=null; try { AndroidHttpClient client = AndroidHttpClient.newInstance(System.getProperty("http.agent")); HttpUriRequest request = new HttpGet(urlString); HttpResponse response = client.execute(request); reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String json = readJSON(reader); client.close(); return parseJSON(json); } catch(IOException e) { e.printStackTrace(); } finally { closeStreams(in, reader); } return new String[0]; }
protected String executeReportPost(MultipartEntity entity) { String url = String.format(URLFormatComponent.getUrl(context, URLFormatComponent.CHAN_POST_URL_DELETE_FORMAT), boardCode);; AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); try { HttpPost request = new HttpPost(url);
@Override public Object invoke(final Object... args) throws InvocationException { final String userAgent = this.buildUserAgent(this.context); final AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent, this.context); try { return this.invoke(client, args); } finally { client.close(); } }
static private Bitmap downloadBitmap(String url) { final AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); final HttpGet getRequest = new HttpGet(url);
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * @param context A {@link Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ @SuppressLint("NewApi") public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link android.content.Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
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 (Log.isLoggable(LogTag.TRANSACTION, Log.DEBUG)) { Log.d(TAG, "[HttpUtils] createHttpClient w/ socket timeout " + soTimeout + " ms, " + ", UA=" + userAgent); } HttpConnectionParams.setSoTimeout(params, soTimeout); return client; }
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { // File cacheDir = new File(EDeviceUtils.getVollyCachePath()); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new NoCache(), network); queue.start(); return queue; }
new HttpClientStack(AndroidHttpClient.newInstance(userAgent)));