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

The following examples show how to use cz.msebera.android.httpclient.impl.client.CloseableHttpClient. 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: HttpClientHelper.java    From BaiduPanApi-Java with MIT License 6 votes vote down vote up
public static CloseableHttpResponse get(CloseableHttpClient httpClient, String url, Map<String, String> params, Map<String, String> headers) throws IOException {

        System.out.println("url:"+url);
        System.out.println("params:"+MapUtil.getEncodedUrl(params));
        System.out.println("headers:"+MapUtil.getEncodedUrl(headers));


        String urlParamString = MapUtil.getEncodedUrl(params);
        if(urlParamString.length()>0){
            if(url.contains("?")){
                url = String.format("%s&%s",url,urlParamString);
            }else{
                url = String.format("%s?%s",url,urlParamString);
            }
        }
        HttpGet httpGet = new HttpGet(url);
        for(Map.Entry<String,String> entry:headers.entrySet()){
            httpGet.setHeader(entry.getKey(),entry.getValue());
        }
        return httpClient.execute(httpGet);
    }
 
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: HttpClientHelper.java    From BaiduPanApi-Java with MIT License 4 votes vote down vote up
public static CloseableHttpResponse get(CloseableHttpClient httpClient, String url) throws IOException {
    return get(httpClient, url,new HashMap<>(),new HashMap<>());
}
 
Example #4
Source File: HttpClientHelper.java    From BaiduPanApi-Java with MIT License 4 votes vote down vote up
public static CloseableHttpResponse post(CloseableHttpClient httpClient, String url, Map<String, String> params,Map<String, String> headers) throws IOException {
    return post(httpClient, url, params, null,headers);
}
 
Example #5
Source File: HttpClientHelper.java    From BaiduPanApi-Java with MIT License 4 votes vote down vote up
public static CloseableHttpResponse post(CloseableHttpClient httpClient, String url,Map<String, String> params) throws IOException {
    return post(httpClient, url, params, new HashMap<>());
}