List of usage examples for org.apache.http.params HttpParams setParameter
HttpParams setParameter(String str, Object obj);
From source file:net.noisetube.io.android.AndroidHttpClient.java
/** * @param agent//from www . ja va 2 s . c o m * * Note: setting the time-outs seems to cause A LOT more connection problems than without, so we don't use them (for now) */ public AndroidHttpClient(String agent) { super(agent); HttpParams httpParameters = new BasicHttpParams(); httpParameters.setParameter("http.useragent", agent); //HttpConnectionParams.setConnectionTimeout(httpParameters, timeout); //Set the timeout in milliseconds until a connection is established //HttpConnectionParams.setSoTimeout(httpParameters, timeout); //Set the default socket timeout in milliseconds which is the timeout for waiting for data. //ConnManagerParams.setTimeout(httpParameters, timeout); final SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); //SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); //sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); //registry.register(new Scheme("https", sslSocketFactory, 443)); final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(httpParameters, registry); httpClient = new DefaultHttpClient(manager, httpParameters); }
From source file:cl.mmoscoso.geocomm.sync.GeoCommGetPointsAsyncTask.java
@Override protected Boolean doInBackground(Void... params) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpPost httppost = new HttpPost(this.hostname); //http://172.16.50.35/~ramirez/testAddPoint.php //http://172.16.57.132/~laost/Symfony/web/app_dev.php/addPoint/ try {// w ww . j a v a2 s . c o m // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("id", Integer.toString(this.id))); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); switch (responseCode) { case 200: HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); //Log.i(TAGNAME, responseBody); JSONObject jObj, point; try { //Log.i(TAGNAME, "tamao: "+ responseBody); jObj = new JSONObject(responseBody); //point = new JSONObject(jObj.getString("point1")); //Log.i(TAGNAME, "tamao22: "+ jObj.length()); //Log.i(TAGNAME, "VER: "+ point.names()); //Log.i(TAGNAME, "tamao: "+ jObj.names().getString(0)); for (int i = 0; i < jObj.length(); i++) { point = new JSONObject(jObj.getString(jObj.names().getString(i))); //Log.i(TAGNAME, "VER2: "+ jObj.getString(jObj.names().getString(i))); points.add(new GeoCommPoint(point.getInt("id"), point.getDouble("longitude"), point.getDouble("latitude"), point.getString("name"), point.getString("description"))); //Log.i(TAGNAME, points.get(i).getName()); //Log.i(TAGNAME, "lat: "+points.get(i).getLatitude()); //Log.i(TAGNAME, "long: "+points.get(i).getLongitude()); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return true; }
From source file:no.kantega.kwashc.server.test.SSLProtocolTest.java
private HttpResponse checkClient(Site site, int httpsPort, HttpClient httpclient, String[] protocols, String[] ciphers) throws NoSuchAlgorithmException, KeyManagementException, IOException { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { allowAllTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000); SSLSocket socket = (SSLSocket) sf.createSocket(params); if (protocols != null) { socket.setEnabledProtocols(protocols); }// w w w . j a v a 2 s . c o m if (ciphers != null) { socket.setEnabledCipherSuites(ciphers); } URL url = new URL(site.getAddress()); InetSocketAddress address = new InetSocketAddress(url.getHost(), httpsPort); sf.connectSocket(socket, address, null, params); Scheme sch = new Scheme("https", httpsPort, sf); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpGet request = new HttpGet( "https://" + url.getHost() + ":" + site.getSecureport() + url.getPath() + "blog"); return httpclient.execute(request); }
From source file:wsattacker.plugin.intelligentdos.requestSender.Http4RequestSenderImpl.java
private void setParamsToClient(HttpClient client) { int timeout = TIMEOUT; if (httpConnectionTimeout > 0) { timeout = httpConnectionTimeout; }/* ww w . j a v a2 s .c o m*/ HttpParams params = client.getParams(); params.setParameter("http.socket.timeout", timeout); params.setParameter("http.connection.timeout", timeout); params.setParameter("http.connection-manager.max-per-host", 3000); params.setParameter("http.connection-manager.max-total", 3000); HttpConnectionParams.setConnectionTimeout(params, timeout); HttpConnectionParams.setSoTimeout(params, timeout); }
From source file:cl.mmoscoso.geocomm.sync.GeoCommCreatePointAsyncTask.java
@Override protected Boolean doInBackground(Void... params) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpPost httppost = new HttpPost(this.hostname); //http://172.16.50.35/~ramirez/testAddPoint.php //http://172.16.57.132/~laost/Symfony/web/app_dev.php/addPoint/ try {/* w ww . j av a 2 s .co m*/ // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("name", this.name)); nameValuePairs.add(new BasicNameValuePair("description", this.desc)); nameValuePairs.add(new BasicNameValuePair("latitude", this.latitude)); nameValuePairs.add(new BasicNameValuePair("longitude", this.longitude)); nameValuePairs.add(new BasicNameValuePair("route", Integer.toString(this.id_route))); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); Log.i(TAGNAME, "ERROR: " + responseCode); switch (responseCode) { default: Log.i(TAGNAME, "ERROR"); //Toast.makeText(this.context,R.string.error_not200code, Toast.LENGTH_SHORT).show(); break; case 200: HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); //Log.i(TAGNAME, responseBody); JSONObject jObj, point; try { Log.i(TAGNAME, "tamao: " + responseBody); jObj = new JSONObject(responseBody); this.status = jObj.getInt("status"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return true; }
From source file:cl.mmoscoso.geocomm.sync.GeoCommCreateRouteAsyncTask.java
@Override protected Boolean doInBackground(Void... params) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpPost httppost = new HttpPost(this.hostname); try {// w ww . j av a2 s .c o m // Add your data Log.i(TAGNAME, "PUBLIC: " + this.is_public); Log.i(TAGNAME, "NAME: " + this.name); Log.i(TAGNAME, "DESC: " + this.desc); Log.i(TAGNAME, "OWNER: " + this.id_user); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("name", this.name)); nameValuePairs.add(new BasicNameValuePair("description", this.desc)); nameValuePairs.add(new BasicNameValuePair("id", Integer.toString(this.id_user))); nameValuePairs.add(new BasicNameValuePair("public", Boolean.toString(this.is_public))); //nameValuePairs.add(new BasicNameValuePair("id", "1")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); Log.i(TAGNAME, "ERROR: " + responseCode); switch (responseCode) { default: Log.i(TAGNAME, "ERROR"); //Toast.makeText(this.context,R.string.error_not200code, Toast.LENGTH_SHORT).show(); break; case 200: HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); Log.i(TAGNAME, responseBody); JSONObject jObj; try { Log.i(TAGNAME, "Status: " + this.is_public); jObj = new JSONObject(responseBody); this.status = jObj.getInt("status"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return true; }
From source file:com.unispezi.cpanelremotebackup.http.HTTPClient.java
public void post(String uri, Map<String, Object> params) { //Construct request HttpRequest request = new HttpPost(uri); Log.debug("Preparing POST of " + getUriLogString(uri)); //set params// w ww .j av a 2s . c om HttpParams httpParams = new BasicHttpParams(); for (String key : params.keySet()) { Object value = params.get(key); httpParams.setParameter(key, value); Log.debug("Adding param " + key + "=" + value); } request.setParams(httpParams); //Post try { Log.debug("POSTing " + getUriLogString(uri)); HttpResponse response = httpClient.execute(host, request, localcontext); Log.debug("Response was " + response); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { Log.info("POSTing " + getUriLogString(uri) + " was successful"); } else { Log.error("POSTing " + getUriLogString(uri) + " failed with status code " + statusCode); throw new HTTPException( "POSTing " + getUriLogString(uri) + " failed with status code " + statusCode); } } catch (IOException e) { Log.error("POSTing " + getUriLogString(uri) + " failed with exception " + e); throw new HTTPException("POSTing " + getUriLogString(uri) + " failed with exception ", e); } }
From source file:bad.robot.http.apache.ApacheHttpClientBuilder.java
private HttpParams createAndConfigureHttpParameters() { HttpParams parameters = createHttpParametersViaNastyHackButBetterThanCopyAndPastingTheApacheSource(); parameters.setParameter(ALLOW_CIRCULAR_REDIRECTS, true); parameters.setParameter(HANDLE_AUTHENTICATION, true); parameters.setParameter(USE_EXPECT_CONTINUE, true); ApacheHttpParameters apache = new ApacheHttpParameters(parameters); handleRedirects.applyTo(apache.configuration(HANDLE_REDIRECTS)); timeout.applyTo(apache.configuration(CONNECTION_TIMEOUT)); timeout.applyTo(apache.configuration(SO_TIMEOUT)); proxy.applyTo(apache.defaultProxy()); return parameters; }
From source file:cl.mmoscoso.geocomm.sync.GeoCommGetRoutesAsyncTask.java
@Override protected Boolean doInBackground(String... params) { // TODO Auto-generated method stub HttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpPost httppost = new HttpPost(this.hostname); Log.i(TAGNAME, "Try to connect to " + this.hostname); try {//w ww . ja va 2 s. co m Log.i(TAGNAME, "Post Request"); HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); Log.i(TAGNAME, "CODE: " + responseCode); switch (responseCode) { default: //Toast.makeText(this.context,R.string.error_not200code, Toast.LENGTH_SHORT).show(); Log.i(TAGNAME, "Error"); break; case 200: HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); //Log.i(TAGNAME, responseBody); JSONObject jObj, ruta; try { Log.i(TAGNAME, "Reading JSONResponse"); //Log.i(TAGNAME, responseBody); jObj = new JSONObject(responseBody); for (int i = 0; i < jObj.length(); i++) { ruta = new JSONObject(jObj.getString(jObj.names().getString(i))); list_routes.add(new GeoCommRoute(ruta.getString("name"), ruta.getString("owner"), ruta.getInt("id"), ruta.getInt("totalPoints"), ruta.getString("description"), ruta.getBoolean("public"))); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block Log.e(TAGNAME, e.toString()); return false; } catch (IOException e) { // TODO Auto-generated catch block Log.e(TAGNAME, e.toString()); return false; } return true; }
From source file:outfox.dict.contest.util.HttpToolKit.java
/** * @param maxConnectPerHost/* w w w . j a v a2s .c o m*/ * @param maxConnection * @param connectTimeOut * @param socketTimeOut * @param cookiePolicy * @param isAutoRetry * @param redirect */ public HttpToolKit(int maxConnectPerHost, int maxConnection, int connectTimeOut, int socketTimeOut, String cookiePolicy, boolean isAutoRetry, boolean redirect) { Scheme https = new Scheme("https", 443, SSLSocketFactory.getSocketFactory()); Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory()); SchemeRegistry sr = new SchemeRegistry(); sr.register(https); sr.register(http); connectionManager = new PoolingClientConnectionManager(sr, socketTimeOut, TimeUnit.MILLISECONDS); connectionManager.setDefaultMaxPerRoute(maxConnectPerHost); connectionManager.setMaxTotal(maxConnection); HttpParams params = new BasicHttpParams(); params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, connectTimeOut); params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, redirect); params.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false); if (isAutoRetry) { client = new AutoRetryHttpClient(new DefaultHttpClient(connectionManager, params)); } else { client = new DefaultHttpClient(connectionManager, params); } }