Android BasicHttpParams - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android BasicHttpParams class.

This code example shows how to use the following methods:
    protected String generateTimestamp() {
         
        long time = -1;
                 
        try { 
            HttpParams httpParams = new BasicHttpParams();
            HttpConnectionParams.setSoTimeout(httpParams, SOCKET_TIMEOUT);
            HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT);
            HttpClient httpClient = new DefaultHttpClient(httpParams);
            HttpGet httpget = new HttpGet(TIMER_URL);
            HttpResponse response = httpClient.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                time = Long.parseLong(EntityUtils.toString(entity),10);
                logger.debug("Got remote timestamp {}", time);
            } 
        } catch (IOException e) {
            logger.warn("Error obtaining the synchronized remote timestamp, defaulting to the local one",e);
        } 
         
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	private Util() { 
	} 
 
	public static HttpParams getTimeoutHttpParams() {
		HttpParams params = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
		HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
		return params;
	} 
 
	public static void closeStream(Closeable stream) {
		if (stream != null) {
			try { 
				stream.close();
				stream = null;
			} catch (IOException e) {
				Log.w(TAG, "Close stream exception", e);
			} 
		} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setIntParameter
 
    return gridClient;
  } 
 
  public HttpParams getHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setSoReuseaddr(params, true);
    HttpConnectionParams.setConnectionTimeout(params, 120 * 1000);
    HttpConnectionParams.setSoTimeout(params, TIMEOUT_THREE_HOURS);
    params.setIntParameter(ConnConnectionPNames.MAX_STATUS_LINE_GARBAGE, 0);
    HttpConnectionParams.setStaleCheckingEnabled(params, true);
    return params;
  } 
 
  public HttpRoutePlanner getRoutePlanner(SchemeRegistry registry) {
    return new ProxySelectorRoutePlanner(registry, ProxySelector.getDefault());
  } 
 
  public HttpParams getGridHttpParams(int connection_timeout, int socket_timeout){
    final HttpParams params = getHttpParams();
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setBooleanParameter, setIntParameter
      connectionManager = localConnectionManager;
       
      int socketTimeout = 900000;
      int connectionTimeout = 60000;
       
      BasicHttpParams params = new BasicHttpParams();
      // This one is essential to prevent us from reading from the content stream before necessary during auth, but 
      // is incompatible with some proxies. 
      params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,true);
      // Enabled for Solr, but probably not necessary for better-behaved ES 
      //params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,true); 
      params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,true);
      params.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS,true);
      params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,socketTimeout);
      params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,connectionTimeout);
      params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,true);
      DefaultHttpClient localClient = new DefaultHttpClient(connectionManager,params);
      // No retries 
      localClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler()
        { 
          public boolean retryRequest( 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setBooleanParameter, setIntParameter
      connectionManager = localConnectionManager;
 
      int socketTimeout = 900000;
      int connectionTimeout = 60000;
       
      BasicHttpParams params = new BasicHttpParams();
      // This one is essential to prevent us from reading from the content stream before necessary during auth, but 
      // is incompatible with some proxies. 
      params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,true);
      // Enabled for Solr, but probably not necessary for better-behaved ES 
      //params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,true); 
      params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,true);
      params.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS,true);
      params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,socketTimeout);
      params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,connectionTimeout);
      params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,true);
      DefaultHttpClient localClient = new DefaultHttpClient(connectionManager,params);
      // No retries 
      localClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler()
        { 
          public boolean retryRequest( 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setParameter
				return new Scheme("http", PlainSocketFactory.getSocketFactory(), port);
			} 
		} 
 
		public org.apache.http.client.HttpClient configureClient() {
			HttpParams params = new BasicHttpParams();
			HttpProtocolParams.setUseExpectContinue(params, useExpectContinue);
			HttpConnectionParams 
					.setConnectionTimeout(params, connectionTimeout);
			HttpConnectionParams.setSoTimeout(params, socketTimeout);
			HttpConnectionParams.setTcpNoDelay(params, Boolean.TRUE);
 
            String protocol = "http";
 
			if (enableSSL)
                protocol = "https";
 
			params.setParameter(ClientPNames.DEFAULT_HOST, new HttpHost(host,
					port, protocol));
			if (proxy != null) {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setDoubleParameter, setParameter
	 
	public InputStream getMessageIDs(double longitude, double latitude, float speed, String sorttype) throws IOException
	{ 
		final String url = "http://" + entrypointHostname + ":" + entrypointPort + "/controller?command=getmessageids";
		HttpGet request = new HttpGet(url);
		BasicHttpParams params = new BasicHttpParams();
		params.setDoubleParameter("longitude", longitude);
		params.setDoubleParameter("latitude", latitude);
		params.setDoubleParameter("speed", speed);
		params.setParameter("sorttype", sorttype);
		request.setParams(params);
		 
		HttpResponse response = null;
		try { 
			response = client.execute(request);
		} 
		catch (HttpHostConnectException e) {
			AndroidLogging.getInstance().error("HTTP Problem: " + e);
			return null; 
		} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	 * @param charset 
	 *            �������뼯, �ɿ� 
	 * @return DefaultHttpClient ���� 
	 */ 
	private static DefaultHttpClient getDefaultHttpClient(final String charset) {
		HttpParams httpParams = new BasicHttpParams();
 
		// �������ӳ�ʱ�� Socket ��ʱ���Լ� Socket ������С 
		HttpConnectionParams.setConnectionTimeout(httpParams, 20 * 1000);
		HttpConnectionParams.setSoTimeout(httpParams, 20 * 1000);
		HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
 
		// �����ض�����ȱʡΪ true 
		HttpClientParams.setRedirecting(httpParams, true);
 
		// ���� user agent 
		String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6";
		HttpProtocolParams.setUserAgent(httpParams, userAgent);
 
		return new DefaultHttpClient(httpParams);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
     * @param context 
     *            : context of activity 
     * @return HttpClient: HttpClient object 
     */ 
    public static HttpClient getHttpClient(Context context) {
        BasicHttpParams httpParameters = new BasicHttpParams();
        // Set the default socket timeout (SO_TIMEOUT) // in 
        // milliseconds which is the timeout for waiting for data. 
        HttpConnectionParams.setConnectionTimeout(httpParameters, Utility.SET_CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParameters, Utility.SET_SOCKET_TIMEOUT);
        HttpClient client = new DefaultHttpClient(httpParameters);
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (!wifiManager.isWifiEnabled()) {
            // 获取当前正在使用的APN接入点 
            Uri uri = Uri.parse("content://telephony/carriers/preferapn");
            Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
            if (mCursor != null && mCursor.moveToFirst()) {
                // 游标移至第一条记录,当然也只有一条 
                String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy"));
                if (proxyStr != null && proxyStr.trim().length() > 0) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setIntParameter
        } catch (IOException expected) {
        } 
    } 
 
    public void testMaxHeaderCount() throws Exception { 
        HttpParams params = new BasicHttpParams();
        SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, params);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
 
        params.setIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, 2);
        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, null, requestFactory, params);
        requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\nHeader: two\r\n\r\n"));
        requestParser.parse();
        requestParser.reset();
 
        try { 
            requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\nHeader: two\r\nHeader: three\r\n\r\n"));
            requestParser.parse();
            fail("IOException should have been thrown");
        } catch (IOException expected) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android BasicHttpParams Questions & Answers:

See Code Examples for Android BasicHttpParams Methods: