Example usage for org.apache.http.params BasicHttpParams BasicHttpParams

List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams

Introduction

In this page you can find the example usage for org.apache.http.params BasicHttpParams BasicHttpParams.

Prototype

public BasicHttpParams() 

Source Link

Usage

From source file:com.antorofdev.util.Http.java

/**
 * Performs http POST petition to server.
 *
 * @param url        URL to perform POST petition.
 * @param parameters Parameters to include in petition.
 *
 * @return Response from the server./*from   w  w  w  .  j a v  a2s . c om*/
 * @throws IOException If the <tt>parameters</tt> have errors, connection timmed out,
 *                     socket timmed out or other error related with the connection occurs.
 */
public static HttpResponse post(String url, ArrayList<NameValuePair> parameters) throws IOException {
    HttpParams httpParameters = new BasicHttpParams();
    int timeoutConnection = 10000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    int timeoutSocket = 10000;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

    HttpClient httpclient = new DefaultHttpClient(httpParameters);
    HttpPost httppost = new HttpPost(url);

    if (parameters != null)
        httppost.setEntity(new UrlEncodedFormEntity(parameters));

    HttpResponse response = httpclient.execute(httppost);

    return response;
}

From source file:org.silvertunnel.netlib.adapter.httpclient.HttpClientUtil.java

static void init(NetLayer lowerNetLayer) {
    try {//from w ww .j a  v a 2  s . c  o  m
        HttpClientUtil.lowerNetLayer = lowerNetLayer;
        Scheme http = new Scheme("http", new NetlibSocketFactory(lowerNetLayer), 80);

        supportedSchemes = new SchemeRegistry();
        supportedSchemes.register(http);

        // prepare parameters
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "UTF-8");
        HttpProtocolParams.setUseExpectContinue(params, true);

        connMgr = new ThreadSafeClientConnManager(params, supportedSchemes);

    } catch (Exception e) {
        log.log(Level.SEVERE, "error during class init", e);
    }
}

From source file:com.entertailion.android.launcher.utils.HttpRequestHelper.java

public static DefaultHttpClient createHttpClient() {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 60000);
    HttpConnectionParams.setSoTimeout(params, 60000);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUserAgent(params,
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.5 Safari/537.22");

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);

    return new DefaultHttpClient(conMgr, params);
}

From source file:org.changhong.sync.web.MySSLSocketFactory.java

public static DefaultHttpClient getNewHttpClient() {
    try {//from   www. j a  v  a 2  s.  com
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(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);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

From source file:org.mango.facebooktext.fbclient.MMConnector.java

public AvatarFbReponseData sendRequest(String id) {
    AvatarFbReponseData responseData = null;
    try {//  w ww.j  a v a  2  s.  co m
        Gson gson = new Gson();

        String link = "https://graph.facebook.com/" + id
                + "/picture?type=normal&redirect=0&width=100&height=100";
        // prepare request
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIME_OUT_CONNECTION);
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIME_OUT_SOCKET);
        HttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpGet postRequest = new HttpGet(link);
        //postRequest.setHeader("Content-Type", "application/json");
        //set session

        // execute request and send response message to MMClientContext
        HttpResponse httpResponse = httpClient.execute(postRequest);
        //System.out.println("response: " + httpResponse);

        /**** handle response for each command ***/
        //extract json Object
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
        // read entire content
        StringBuilder buffer = new StringBuilder();
        String ln;
        while ((ln = reader.readLine()) != null) {
            buffer.append(ln);
        }
        if (buffer.length() == 0) {
            // empty? do something... 
            throw new Exception("Empty response");
        } else {
            responseData = gson.fromJson(buffer.toString(), AvatarFbReponseData.class);
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // are you sure you have to do this?
        //           httpClient.getConnectionManager().shutdown();
    }
    return responseData;
}

From source file:android.net.http.HttpConnection.java

/**
 * Opens the connection to a http server
 *
 * @return the opened low level connection
 * @throws IOException if the connection fails for any reason.
 *//*from  ww  w.ja  v  a  2s.  co  m*/
@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;
}

From source file:outfox.ynote.open.client.YNoteHttpUtils.java

/**
 * Do a http get for the given url.//  w w  w .j  a va  2  s .c o m
 *
 * @param url requested url
 * @param parameters request parameters
 * @param accessor oauth accessor
 * @return the http response
 * @throws IOException
 * @throws {@link YNoteException}
 */
public static HttpResponse doGet(String url, Map<String, String> parameters, OAuthAccessor accessor)
        throws IOException, YNoteException {
    // add ynote parameters to the url
    OAuth.addParameters(url, parameters == null ? null : parameters.entrySet());
    HttpGet get = new HttpGet(url);
    // sign all parameters, including oauth parameters and ynote parameters
    // and add the oauth related information into the header        
    Header oauthHeader = getAuthorizationHeader(url, OAuthMessage.GET, parameters, accessor);
    get.addHeader(oauthHeader);
    HttpParams params = new BasicHttpParams();
    HttpClientParams.setRedirecting(params, false);
    get.setParams(params);
    HttpResponse response = client.execute(get);
    if ((response.getStatusLine().getStatusCode() / 100) != 2) {
        YNoteException e = wrapYNoteException(response);
        throw e;
    }
    return response;
}

From source file:ru.algorithmist.jquant.infr.GAEHTTPClient.java

public GAEHTTPClient() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    BasicHttpParams params = new BasicHttpParams();
    GAEConnectionManager connmgr = new GAEConnectionManager();
    client = new DefaultHttpClient(connmgr, params);
    client.getParams().setParameter("User-Agent",
            "Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1");
}

From source file:com.wialon.remote.ApacheSdkHttpClient.java

private static BasicHttpParams getBasicHttpParams(int timeout) {
    BasicHttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8);
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    return params;
}

From source file:hoahong.facebook.messenger.fbclient.MMConnector.java

public AvatarFbReponseData sendRequest(String id, int size) {
    AvatarFbReponseData responseData = null;
    try {/* ww w .  j  av  a  2s.c  o m*/
        Gson gson = new Gson();

        String link = "https://graph.facebook.com/" + id + "/picture?type=normal&redirect=0&width=" + size
                + "&height=" + size;
        // prepare request
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIME_OUT_CONNECTION);
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIME_OUT_SOCKET);
        HttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpGet postRequest = new HttpGet(link);
        //postRequest.setHeader("Content-Type", "application/json");
        //set session

        // execute request and send response message to MMClientContext
        HttpResponse httpResponse = httpClient.execute(postRequest);
        //System.out.println("response: " + httpResponse);

        /**** handle response for each command ***/
        //extract json Object
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
        // read entire content
        StringBuilder buffer = new StringBuilder();
        String ln;
        while ((ln = reader.readLine()) != null) {
            buffer.append(ln);
        }
        if (buffer.length() == 0) {
            // empty? do something... 
            throw new Exception("Empty response");
        } else {
            responseData = gson.fromJson(buffer.toString(), AvatarFbReponseData.class);
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // are you sure you have to do this?
        //           httpClient.getConnectionManager().shutdown();
    }
    return responseData;
}