Search in sources :

Example 26 with HttpParams

use of org.apache.http.params.HttpParams 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;
}
Also used : HttpParams(org.apache.http.params.HttpParams) AndroidHttpClient(android.net.http.AndroidHttpClient)

Example 27 with HttpParams

use of org.apache.http.params.HttpParams in project ignition by mttkay.

the class IgnitedHttp method updateProxySettings.

/**
     * Updates the underlying HTTP client's proxy settings with what the user has entered in the APN
     * settings. This will be called automatically if {@link #listenForConnectivityChanges(Context)}
     * has been called. <b>This requires the {@link Manifest.permission#ACCESS_NETWORK_STATE}
     * permission</b>.
     * 
     * @param context
     *            the current context
     */
public void updateProxySettings(Context context) {
    if (context == null) {
        return;
    }
    HttpParams httpParams = httpClient.getParams();
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo nwInfo = connectivity.getActiveNetworkInfo();
    if (nwInfo == null) {
        return;
    }
    Log.i(LOG_TAG, nwInfo.toString());
    if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        String proxyHost = Proxy.getHost(context);
        if (proxyHost == null) {
            proxyHost = Proxy.getDefaultHost();
        }
        int proxyPort = Proxy.getPort(context);
        if (proxyPort == -1) {
            proxyPort = Proxy.getDefaultPort();
        }
        if (proxyHost != null && proxyPort > -1) {
            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        } else {
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
        }
    } else {
        httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
    }
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) HttpHost(org.apache.http.HttpHost)

Example 28 with HttpParams

use of org.apache.http.params.HttpParams in project custom-cert-https by nelenkov.

the class MainActivity method createHttpClient.

private HttpClient createHttpClient(SocketFactory socketFactory) {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
    ConnPerRoute connPerRoute = new ConnPerRouteBean(MAX_CONN_PER_ROUTE);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
    ConnManagerParams.setMaxTotalConnections(params, MAX_CONNECTIONS);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    SocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    if (socketFactory != null) {
        sslSocketFactory = socketFactory;
    }
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    return new DefaultHttpClient(cm, params);
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) SocketFactory(org.apache.http.conn.scheme.SocketFactory) PlainSocketFactory(org.apache.http.conn.scheme.PlainSocketFactory) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) ConnPerRoute(org.apache.http.conn.params.ConnPerRoute) BasicHttpParams(org.apache.http.params.BasicHttpParams) ConnPerRouteBean(org.apache.http.conn.params.ConnPerRouteBean) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 29 with HttpParams

use of org.apache.http.params.HttpParams in project openhab1-addons by openhab.

the class StreamClientImpl method getRequestParams.

protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();
    localParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1);
    // DefaultHttpClient adds HOST header automatically in its default processor
    // Let's add the user-agent header on every request
    HttpProtocolParams.setUserAgent(localParams, getConfiguration().getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion()));
    return new DefaultedHttpParams(localParams, globalParams);
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) DefaultedHttpParams(org.apache.http.params.DefaultedHttpParams) HttpParams(org.apache.http.params.HttpParams) BasicHttpParams(org.apache.http.params.BasicHttpParams) DefaultedHttpParams(org.apache.http.params.DefaultedHttpParams)

Example 30 with HttpParams

use of org.apache.http.params.HttpParams in project mobile-android by photo.

the class ApiBase method execute.

/**
     * Execute a request to the API.
     * 
     * @param request request to perform
     * @param baseUrl the base server url
     * @param consumer the oauth consumer key to sign request
     * @param listener Progress Listener with callback on progress
     * @param connectionTimeout the connection and socket timeout
     * @return the response from the API
     * @throws ClientProtocolException
     * @throws IOException
     */
public ApiResponse execute(ApiRequest request, String baseUrl, OAuthConsumer consumer, ProgressListener listener, int connectionTimeout) throws ClientProtocolException, IOException {
    // PoolingClientConnectionManager();
    HttpParams params = new BasicHttpParams();
    // set params for connection...
    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
    HttpConnectionParams.setSoTimeout(params, connectionTimeout);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    DefaultHttpClient httpClient = new DefaultHttpClient(params);
    HttpUriRequest httpRequest = createHttpRequest(request, baseUrl, listener);
    httpRequest.getParams().setBooleanParameter("http.protocol.expect-continue", false);
    httpRequest.setHeader("User-Agent", "android");
    httpRequest.setHeader("source", "android");
    if (consumer != null) {
        try {
            consumer.sign(httpRequest);
        } catch (Exception e) {
            GuiUtils.noAlertError(TAG, "Error signing request", e);
        }
    } else {
        TrackerUtils.trackBackgroundEvent("not_signed_request", baseUrl + request.getPath());
    }
    return new ApiResponse(baseUrl + request.getPath(), httpClient.execute(httpRequest));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) BasicHttpParams(org.apache.http.params.BasicHttpParams) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

HttpParams (org.apache.http.params.HttpParams)121 BasicHttpParams (org.apache.http.params.BasicHttpParams)85 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)43 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)31 Scheme (org.apache.http.conn.scheme.Scheme)30 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)28 IOException (java.io.IOException)27 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)27 HttpResponse (org.apache.http.HttpResponse)24 HttpHost (org.apache.http.HttpHost)23 Header (org.apache.http.Header)18 HttpGet (org.apache.http.client.methods.HttpGet)13 URI (java.net.URI)10 HttpRequest (org.apache.http.HttpRequest)10 HttpClient (org.apache.http.client.HttpClient)10 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)10 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)10 Socket (java.net.Socket)9 ClientProtocolException (org.apache.http.client.ClientProtocolException)9 GeneralSecurityException (java.security.GeneralSecurityException)8