List of usage examples for org.apache.http.client.methods CloseableHttpResponse getEntity
HttpEntity getEntity();
From source file:siddur.solidtrust.azure.AzureCarConstants.java
public static void main(String[] args) throws Exception { String url = OPENDATA_RWD_CSV_POST_URL; HttpPost request = new HttpPost(url); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("view", VIEW)); nvps.add(new BasicNameValuePair("method", METHOD)); request.setEntity(new UrlEncodedFormEntity(nvps)); CloseableHttpClient httpClient = HttpClients.custom().build(); CloseableHttpResponse response = httpClient.execute(request); InputStream is = response.getEntity().getContent(); IOUtils.copy(is, System.out); }
From source file:com.http.ClientAuthentication.java
public static void main(String[] args) throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope("localhost", 443), new UsernamePasswordCredentials("username", "password")); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); try {/*from w w w. j a va 2 s.c om*/ HttpGet httpget = new HttpGet("https://localhost/protected"); System.out.println("executing request" + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:cn.anthony.util.ClientCustomSSL.java
public final static void main(String[] args) throws Exception { // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new File("my.keystore"), "nopassword".toCharArray(), new TrustSelfSignedStrategy()).build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try {// w w w. j a v a2 s. c om HttpGet httpget = new HttpGet("https://httpbin.org/"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.zhch.example.commons.http.v4_5.ClientCustomSSL.java
public final static void main(String[] args) throws Exception { // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom() .loadTrustMaterial(new File("d:\\workspace_mars\\resume_import_system\\jssecacerts"), null, new TrustSelfSignedStrategy()) .build();//from ww w .j av a 2s. c om // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try { HttpGet httpget = new HttpGet("https://passport.zhaopin.com/org/login"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.lxf.spider.client.ClientCustomSSL.java
public final static void main(String[] args) throws Exception { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream instream = new FileInputStream(new File("my.keystore")); try {//from www. j a va 2s.c o m trustStore.load(instream, "nopassword".toCharArray()); } finally { instream.close(); } // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()) .build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try { HttpGet httpget = new HttpGet("https://localhost/"); System.out.println("executing request" + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:test.ClientCustomSSL.java
public final static void main(String[] args) throws Exception { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream instream = new FileInputStream(new File("D:\\keystore.jks")); try {/*w w w. j a v a 2 s .c o m*/ trustStore.load(instream, "password".toCharArray()); } finally { instream.close(); } // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()) .build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try { HttpGet httpget = new HttpGet("https://retail.onlinesbi.com/personal/css/style.css"); System.out.println("executing request" + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:interoperabilite.webservice.client.ClientCustomPublicSuffixList.java
public final static void main(String[] args) throws Exception { // Use PublicSuffixMatcherLoader to load public suffix list from a file, // resource or from an arbitrary URL PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader .load(new URL("https://publicsuffix.org/list/effective_tld_names.dat")); // Please use the publicsuffix.org URL to download the list no more than once per day !!! // Please consider making a local copy !!! DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher); RFC6265CookieSpecProvider cookieSpecProvider = new RFC6265CookieSpecProvider(publicSuffixMatcher); Lookup<CookieSpecProvider> cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create() .register(CookieSpecs.DEFAULT, cookieSpecProvider) .register(CookieSpecs.STANDARD, cookieSpecProvider) .register(CookieSpecs.STANDARD_STRICT, cookieSpecProvider).build(); CloseableHttpClient httpclient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier) .setDefaultCookieSpecRegistry(cookieSpecRegistry).build(); try {//from w w w .j a v a2 s . c o m HttpGet httpget = new HttpGet("https://httpbin.org/"); System.out.println("executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:an.dpr.cyclingresultsapi.ClientExecuteProxy.java
public static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); StringBuilder ret = new StringBuilder(); try {// w w w .jav a 2s . com //http://cyclingresults-dprsoft.rhcloud.com/rest/competitions/query/20140101,20140601,1,1,UWT // HttpHost target = new HttpHost("cyclingresults-dprsoft.rhcloud.com", 80, "http"); HttpHost proxy = null;// = new HttpHost("proxy.sdc.hp.com", 8080, "http"); HttpHost target = new HttpHost("localhost", 8282, "http"); RequestConfig config = RequestConfig.custom() // .setProxy(proxy) .build(); HttpGet request = new HttpGet("/rest/competitions/query/20130801,20130901,1,1,UWT"); request.setConfig(config); System.out.println("Executing request " + request.getRequestLine() + " to " + target + " via " + proxy); CloseableHttpResponse response = httpclient.execute(target, request); InputStreamReader isr = new InputStreamReader(response.getEntity().getContent(), "cp1252"); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { ret.append(line); } try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); } finally { response.close(); } } finally { httpclient.close(); } System.out.println(ret.toString()); }
From source file:ddu.core.httpclient.ClientCustomSSL.java
public final static void main(String[] args) throws Exception { // Trust own CA and all self-signed certs KeyStore trustKeyStore = KeyStore.getInstance("JKS"); // get user password and file input stream char[] password = "123456".toCharArray(); java.io.FileInputStream fis = null; try {//ww w. j a v a 2 s. c o m fis = new java.io.FileInputStream("keyStoreName"); trustKeyStore.load(fis, password); } finally { if (fis != null) { fis.close(); } } SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustKeyStore, new TrustSelfSignedStrategy()) .build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try { HttpGet httpget = new HttpGet("https://httpbin.org/"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:org.datagator.api.client.backend.DataGatorService.java
public static void main(String[] args) throws Exception { UsernamePasswordCredentials auth = null; String credentials = environ.DATAGATOR_CREDENTIALS; if (credentials != null) { String[] tuple = credentials.split(".", 1); if (tuple.length > 1) { auth = new UsernamePasswordCredentials(tuple[0], tuple[1]); } else if (tuple.length > 0) { auth = new UsernamePasswordCredentials(tuple[0], null); }// w ww. j a va2 s . c o m } final DataGatorService service; if (auth != null) { service = new DataGatorService(auth); } else { service = new DataGatorService(); } CloseableHttpResponse response = service.get("/"); response.getEntity().writeTo(System.out); response.close(); // JsonParser parser = json.createParser(stream); }