List of usage examples for org.apache.http.client HttpClient getParams
@Deprecated HttpParams getParams();
From source file:com.redwoodsystems.android.apps.utils.HttpUtil.java
public static void setBasicAuthCredentials(HttpClient client, String userName, String password) { //BASIC Authentication List<String> authPrefs = new ArrayList<String>(2); authPrefs.add(AuthPolicy.BASIC);// w w w . j a va2 s .c o m client.getParams().setParameter("http.auth.scheme-pref", authPrefs); ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(org.apache.http.auth.AuthScope.ANY, new UsernamePasswordCredentials(userName, password)); }
From source file:com.example.aliyundemo.ocr.util.HttpUtil.java
/** * HTTP POST //from w w w .ja v a 2 s .co m * * @param url http://host+path+query * @param headers Http * @param bytes * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPost(String url, Map<String, String> headers, byte[] bytes, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.POST, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPost post = new HttpPost(url); for (Map.Entry<String, String> e : headers.entrySet()) { post.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue())); } if (bytes != null) { post.setEntity(new ByteArrayEntity(bytes)); } return httpClient.execute(post); }
From source file:com.example.aliyundemo.ocr.util.HttpUtil.java
public static HttpResponse httpsPost(String url, Map<String, String> headers, byte[] bytes, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.POST, url, null, signHeaderPrefixList); //HttpClient httpClient = new SSLClient(); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPost post = new HttpPost(url); for (Map.Entry<String, String> e : headers.entrySet()) { post.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue())); }/*from w w w. j av a 2s. com*/ if (bytes != null) { post.setEntity(new ByteArrayEntity(bytes)); } return httpClient.execute(post); }
From source file:com.example.aliyundemo.ocr.util.HttpUtil.java
/** * HTTP PUT /*from ww w .j ava 2 s . c om*/ * * @param url http://host+path+query * @param headers Http * @param body * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPut(String url, Map<String, String> headers, String body, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.PUT, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPut put = new HttpPut(url); for (Map.Entry<String, String> e : headers.entrySet()) { put.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue())); } if (StringUtils.isNotBlank(body)) { put.setEntity(new StringEntity(body, Constants.ENCODING)); } return httpClient.execute(put); }
From source file:com.example.aliyundemo.ocr.util.HttpUtil.java
/** * HTTP PUT// ww w . jav a 2 s . c om * * @param url http://host+path+query * @param headers Http * @param bytes * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPut(String url, Map<String, String> headers, byte[] bytes, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.PUT, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPut put = new HttpPut(url); for (Map.Entry<String, String> e : headers.entrySet()) { put.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue())); } if (bytes != null) { put.setEntity(new ByteArrayEntity(bytes)); } return httpClient.execute(put); }
From source file:com.example.aliyundemo.ocr.util.HttpUtil.java
/** * HTTP POST?/*from w w w . jav a 2 s .co m*/ * * @param url http://host+path+query * @param headers Http * @param formParam ?? * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPost(String url, Map<String, String> headers, Map<String, String> formParam, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { if (headers == null) { headers = new HashMap<String, String>(); } headers.put(HttpHeader.HTTP_HEADER_CONTENT_TYPE, ContentType.CONTENT_TYPE_FORM); headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.POST, url, formParam, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPost post = new HttpPost(url); for (Map.Entry<String, String> e : headers.entrySet()) { post.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue())); } UrlEncodedFormEntity formEntity = buildFormEntity(formParam); if (formEntity != null) { post.setEntity(formEntity); } return httpClient.execute(post); }
From source file:com.investoday.code.util.aliyun.api.gateway.util.HttpUtil.java
/** * HTTP DELETE// w w w . j a va 2 s .c om * * @param url http://host+path+query * @param headers Http * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpDelete(String url, Map<String, String> headers, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.DELETE, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpDelete delete = new HttpDelete(url); for (Map.Entry<String, String> e : headers.entrySet()) { delete.addHeader(e.getKey(), e.getValue()); } return httpClient.execute(delete); }
From source file:com.investoday.code.util.aliyun.api.gateway.util.HttpUtil.java
/** * Http POST //from ww w .jav a2s. c o m * * @param url http://host+path+query * @param headers Http * @param body * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPost(String url, Map<String, String> headers, String body, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.POST, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPost post = new HttpPost(url); for (Map.Entry<String, String> e : headers.entrySet()) { post.addHeader(e.getKey(), e.getValue()); } if (StringUtils.isNotBlank(body)) { post.setEntity(new StringEntity(body, Constants.ENCODING)); } return httpClient.execute(post); }
From source file:com.investoday.code.util.aliyun.api.gateway.util.HttpUtil.java
/** * HTTP POST /*from w w w. j a v a2 s. c o m*/ * * @param url http://host+path+query * @param headers Http * @param bytes * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPost(String url, Map<String, String> headers, byte[] bytes, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.POST, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPost post = new HttpPost(url); for (Map.Entry<String, String> e : headers.entrySet()) { post.addHeader(e.getKey(), e.getValue()); } if (bytes != null) { post.setEntity(new ByteArrayEntity(bytes)); } return httpClient.execute(post); }
From source file:com.investoday.code.util.aliyun.api.gateway.util.HttpUtil.java
/** * HTTP PUT /*from w ww . ja va 2 s . c om*/ * * @param url http://host+path+query * @param headers Http * @param body * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPut(String url, Map<String, String> headers, String body, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.PUT, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPut put = new HttpPut(url); for (Map.Entry<String, String> e : headers.entrySet()) { put.addHeader(e.getKey(), e.getValue()); } if (StringUtils.isNotBlank(body)) { put.setEntity(new StringEntity(body, Constants.ENCODING)); } return httpClient.execute(put); }