cz.msebera.android.httpclient.impl.client.HttpClients Java Examples

The following examples show how to use cz.msebera.android.httpclient.impl.client.HttpClients. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtendedHttpClient.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private static HttpClient build(final HttpHost proxy, CookieStore cookieStore) {
    SSLCompatibility.waitIfInstallingAsync();
    return HttpClients.custom().
            setDefaultRequestConfig(getDefaultRequestConfigBuilder(HttpConstants.DEFAULT_HTTP_TIMEOUT).build()).
            setUserAgent(HttpConstants.USER_AGENT_STRING).
            setProxy(proxy).
            setDefaultCookieStore(cookieStore).
            setSSLSocketFactory(ExtendedSSLSocketFactory.getSocketFactory()).
            build();
}
 
Example #2
Source File: MainActivity.java    From httpclient-android with Apache License 2.0 5 votes vote down vote up
@Override
protected String doInBackground(Void... voids) {
    String ret = null;
    CloseableHttpClient chc = HttpClients.createDefault();
    try {
        CloseableHttpResponse chr = chc.execute(HttpHost.create("https://httpbin.org"), new HttpGet("/headers"));
        ret = EntityUtils.toString(chr.getEntity());
        chr.close();
        chc.close();
    } catch (Exception e) {
        Log.e("HttpTest", e.getMessage(), e);
        ret = e.getMessage();
    }
    return ret;
}
 
Example #3
Source File: BaseClass.java    From BaiduPanApi-Java with MIT License 5 votes vote down vote up
BaseClass(String username,String password,String apiTemplate,BaseRunnable captchaRunnable) throws Exception {
        if(apiTemplate==null){
            apiTemplate = BaseData.apiTemplate;
        }

        try {
            //通过代理访问
//            session = HttpClients.custom().useSystemProperties()
//                    .setDefaultCookieStore(cookieStore).setProxy(new HttpHost("127.0.0.1", 4443)).setConnectionManager(HttpClientHelper.getSSLNoCheckConnectionManager())
//                    .build();
            //正常访问
             session = HttpClients.custom().useSystemProperties()
                     .setDefaultCookieStore(cookieStore).setConnectionManager(HttpClientHelper.getSSLNoCheckConnectionManager())
             .build();
        }catch (NoClassDefFoundError e){
            //通过代理访问
//            session = HttpClients.custom()
//                    .setDefaultCookieStore(cookieStore).setProxy(new HttpHost("127.0.0.1", 4443)).setConnectionManager(HttpClientHelper.getSSLNoCheckConnectionManager())
//                    .build();
            //正常访问
             session = HttpClients.custom()
             .setDefaultCookieStore(cookieStore).setConnectionManager(HttpClientHelper.getSSLNoCheckConnectionManager())
             .build();
        }
        this.apiTemplate = apiTemplate;
        this.username = username;
        this.password = password;
        if(captchaRunnable != null){
            this.captchaRunnable = captchaRunnable;
        }else{
            this.captchaRunnable = new ShowCaptchaRunnable();
        }
        this.progressRunnable = null;

        System.out.println("设置pcs服务器");
        setPcsServer(getFastestPcsServer());

        initiate();
    }