Search in sources :

Example 71 with BasicHttpParams

use of org.apache.http.params.BasicHttpParams in project XobotOS by xamarin.

the class AndroidHttpClient method newInstance.

/**
     * Create a new HttpClient with reasonable defaults (which you can update).
     *
     * @param userAgent to report in your HTTP requests
     * @param context to use for caching SSL sessions (may be null for no caching)
     * @return AndroidHttpClient for you to use for all your requests.
     */
public static AndroidHttpClient newInstance(String userAgent, Context context) {
    HttpParams params = new BasicHttpParams();
    // Turn off stale checking.  Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    // Don't handle redirects -- return them to the caller.  Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);
    // Use a session cache for SSL sockets
    SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);
    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLCertificateSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT, sessionCache), 443));
    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
    // parameters without the funny call-a-static-method dance.
    return new AndroidHttpClient(manager, 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) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSessionCache(android.net.SSLSessionCache) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager)

Example 72 with BasicHttpParams

use of org.apache.http.params.BasicHttpParams in project XobotOS by xamarin.

the class HttpConnection method openConnection.

/**
     * Opens the connection to a http server
     *
     * @return the opened low level connection
     * @throws IOException if the connection fails for any reason.
     */
@Override
AndroidHttpClientConnection openConnection(Request req) throws IOException {
    // Update the certificate info (connection not secure - set to null)
    EventHandler eventHandler = req.getEventHandler();
    mCertificate = null;
    eventHandler.certificate(mCertificate);
    AndroidHttpClientConnection conn = new AndroidHttpClientConnection();
    BasicHttpParams params = new BasicHttpParams();
    Socket sock = new Socket(mHost.getHostName(), mHost.getPort());
    params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8192);
    conn.bind(sock, params);
    return conn;
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) Socket(java.net.Socket)

Example 73 with BasicHttpParams

use of org.apache.http.params.BasicHttpParams in project XobotOS by xamarin.

the class DefaultHttpClient method createHttpParams.

@Override
protected HttpParams createHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    /*
         * Android note: Send each request body without first asking the server
         * whether it will be accepted. Asking first slows down the common case
         * and results in "417 expectation failed" errors when a HTTP/1.0 server
         * is behind a proxy. http://b/2471595
         */
    HttpProtocolParams.setUseExpectContinue(params, // android-changed
    false);
    // determine the release version from packaged version info
    final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
    final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;
    HttpProtocolParams.setUserAgent(params, "Apache-HttpClient/" + release + " (java 1.4)");
    return params;
}
Also used : VersionInfo(org.apache.http.util.VersionInfo) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) BasicHttpParams(org.apache.http.params.BasicHttpParams)

Example 74 with BasicHttpParams

use of org.apache.http.params.BasicHttpParams in project 360-Engine-for-Android by 360.

the class PollThread method setHttpClient.

private void setHttpClient() {
    int connectionTimeout = 2 * Settings.HTTP_CONNECTION_TIMEOUT;
    HttpParams myHttpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myHttpParams, connectionTimeout);
    HttpConnectionParams.setSoTimeout(myHttpParams, connectionTimeout);
    mHttpClient = new DefaultHttpClient(myHttpParams);
}
Also used : 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)

Example 75 with BasicHttpParams

use of org.apache.http.params.BasicHttpParams in project ABPlayer by winkstu.

the class HttpUtil method httpGetNoResult.

public static String httpGetNoResult(String url) {
    System.out.println("httpGetNo" + url);
    HttpGet httpget = new HttpGet(hostBase + url);
    String strResult = "";
    BasicHttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
    HttpConnectionParams.setSoTimeout(httpParams, 10000);
    HttpClient httpclient;
    try {
        httpclient = new DefaultHttpClient(httpParams);
        httpget.setHeader("Cookie", cookieName + "=" + cookieValue);
        HttpResponse response = httpclient.execute(httpget);
        System.out.println(response.getStatusLine().getStatusCode());
    /*
			 * if(response.getStatusLine().getStatusCode() == 200){ strResult =
			 * EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
			 * System.out.println(strResult); System.out.println("getFinish"); }
			 */
    } catch (Exception e) {
        e.printStackTrace();
        strResult = "error";
    }
    return strResult;
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) BasicHttpParams(org.apache.http.params.BasicHttpParams) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ProtocolException(org.apache.http.ProtocolException) ClientProtocolException(org.apache.http.client.ClientProtocolException) DataFormatException(java.util.zip.DataFormatException) ConnectException(java.net.ConnectException) IOException(java.io.IOException)

Aggregations

BasicHttpParams (org.apache.http.params.BasicHttpParams)82 HttpParams (org.apache.http.params.HttpParams)62 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)47 IOException (java.io.IOException)33 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)31 Scheme (org.apache.http.conn.scheme.Scheme)30 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)29 HttpResponse (org.apache.http.HttpResponse)27 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)24 ClientProtocolException (org.apache.http.client.ClientProtocolException)15 HttpClient (org.apache.http.client.HttpClient)12 HttpGet (org.apache.http.client.methods.HttpGet)12 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)12 Socket (java.net.Socket)11 HttpPost (org.apache.http.client.methods.HttpPost)10 ConnectException (java.net.ConnectException)8 KeyManagementException (java.security.KeyManagementException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 SSLContext (javax.net.ssl.SSLContext)8 StringEntity (org.apache.http.entity.StringEntity)8