List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams
public BasicHttpParams()
From source file:com.devbliss.doctest.httpfactory.PostUploadWithoutRedirectImpl.java
public HttpPost createPostRequest(URI uri, Object payload) throws IOException { HttpPost httpPost = new HttpPost(uri); HttpParams params = new BasicHttpParams(); params.setParameter(HttpConstants.HANDLE_REDIRECTS, false); httpPost.setParams(params);// w w w . ja v a 2 s .c o m MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart(paramName, fileBodyToUpload); httpPost.setEntity(entity); return httpPost; }
From source file:fi.iki.dezgeg.matkakorttiwidget.matkakortti.NonverifyingSSLSocketFactory.java
public static AbstractHttpClient createNonverifyingHttpClient() throws Exception { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null);// ww w . j a va 2s. c o m SSLSocketFactory sf = new NonverifyingSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); }
From source file:com.devbliss.doctest.httpfactory.DeleteWithoutRedirectImpl.java
public HttpDeleteWithBody createDeleteRequest(URI uri, Object payload) throws IOException { HttpDeleteWithBody httpDelete = new HttpDeleteWithBody(uri); HttpParams params = new BasicHttpParams(); params.setParameter(HANDLE_REDIRECTS, false); httpDelete.setParams(params);//from w w w . jav a 2 s. c om if (payload != null) { httpDelete.setEntity(entityBuilder.buildEntity(payload)); } return httpDelete; }
From source file:org.transdroid.util.HttpHelper.java
public static HttpClient buildDefaultSearchHttpClient(boolean ignoreSslIssues) { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", ignoreSslIssues ? new IgnoreTlsSniSocketFactory() : new TlsSniSocketFactory(), 443)); HttpParams httpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams, 8000); HttpConnectionParams.setSoTimeout(httpparams, 8000); DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry), httpparams);/*from w ww . j a va2s . c o m*/ httpclient.addRequestInterceptor(HttpHelper.gzipRequestInterceptor); httpclient.addResponseInterceptor(HttpHelper.gzipResponseInterceptor); return httpclient; }
From source file:com.example.hnreader.Download.java
/** * Make Http request to the url and return webpage as string; * * @param url/* w ww.ja v a 2 s . c om*/ * @return */ private String getPage(String url) { HttpParams httpParameters = new BasicHttpParams(); int timeoutSocket = 5000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutSocket); HttpConnectionParams.setTcpNoDelay(httpParameters, true); HttpResponse response; StringBuilder str = new StringBuilder(); HttpClient client = new DefaultHttpClient(httpParameters); HttpGet request = new HttpGet(url); try { response = client.execute(request); InputStream in = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { str.append(line); } in.close(); } catch (Exception e) { return ""; } return str.toString(); }
From source file:org.thoughtcrime.ssl.pinning.util.PinningHelper.java
/** * Constructs an HttpClient that will validate SSL connections with a PinningTrustManager. * * @param pins An array of encoded pins to match a seen certificate * chain against. A pin is a hex-encoded hash of a X.509 certificate's * SubjectPublicKeyInfo. A pin can be generated using the provided pin.py * script: python ./tools/pin.py certificate_file.pem *///from w w w . j a va2s. c o m public static HttpClient getPinnedHttpClient(Context context, String[] pins) { try { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", new PinningSSLSocketFactory(context, pins, 0), 443)); HttpParams httpParams = new BasicHttpParams(); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry); return new DefaultHttpClient(connectionManager, httpParams); } catch (UnrecoverableKeyException e) { throw new AssertionError(e); } catch (KeyManagementException e) { throw new AssertionError(e); } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); } catch (KeyStoreException e) { throw new AssertionError(e); } }
From source file:be.uclouvain.multipathcontrol.stats.HttpUtils.java
/** * @param timeout in ms// www . j a v a2 s . c o m * @return BasicHttpParams with timeout for the connection and the socket */ private static HttpParams getParamTimeout(int timeout) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, timeout); HttpConnectionParams.setSoTimeout(httpParameters, timeout); return httpParameters; }
From source file:me.nytyr.simplebitmapcache.http.HttpBitmapGetter.java
@Override public Bitmap get(final String URL) { // Making HTTP request try {/*w w w . ja v a 2 s. c o m*/ final HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, httpTimeout); HttpConnectionParams.setSoTimeout(httpParams, httpTimeout); HttpConnectionParams.setTcpNoDelay(httpParams, true); ConnManagerParams.setTimeout(httpParams, httpTimeout); DefaultHttpClient httpClient = new DefaultHttpClient(httpParams); HttpGet httpPost = new HttpGet(URL); HttpResponse httpResponse = httpClient.execute(httpPost); StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); HttpEntity httpEntity = httpResponse.getEntity(); final FlushedInputStream is = new FlushedInputStream(httpEntity.getContent()); if (statusCode != 200) { Log.e(TAG, "Error downloading image. Status code > " + statusCode); return null; } return BitmapFactory.decodeStream(is); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.blork.anpod.util.SyncUtils.java
/** * Generate and return a {@link HttpClient} configured for general use, * including setting an application-specific user-agent string. * * @param context the context//from w ww .j a va 2 s . com * @return the http client */ static HttpClient getHttpClient(Context context) { final HttpParams params = new BasicHttpParams(); // Use generous timeouts for slow mobile networks HttpConnectionParams.setConnectionTimeout(params, 20 * SECOND_IN_MILLIS); HttpConnectionParams.setSoTimeout(params, 20 * SECOND_IN_MILLIS); HttpConnectionParams.setSocketBufferSize(params, 8192); HttpProtocolParams.setUserAgent(params, buildUserAgent(context)); final DefaultHttpClient client = new DefaultHttpClient(params); client.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) { // Add header to accept gzip content if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } } }); client.addResponseInterceptor(new HttpResponseInterceptor() { public void process(HttpResponse response, HttpContext context) { // Inflate any responses compressed with gzip final HttpEntity entity = response.getEntity(); final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); return client; }