List of usage examples for org.apache.http.client.methods CloseableHttpResponse getEntity
HttpEntity getEntity();
From source file:PostMethodMyExample.java
public static void main(String[] args) throws Exception { BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); try {//w w w . j a v a 2s . c o m HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt"); CloseableHttpResponse response1 = httpclient.execute(httpget); try { HttpEntity entity = response1.getEntity(); System.out.println("Login form get: " + response1.getStatusLine()); EntityUtils.consume(entity); System.out.println("Initial set of cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response1.close(); } HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?" + "org=self_registered_users&" + "goto=/portal/dt&" + "gotoOnFail=/portal/dt?error=true"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("IDToken1", "username")); nvps.add(new BasicNameValuePair("IDToken2", "password")); httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); CloseableHttpResponse response2 = httpclient.execute(httpost); try { HttpEntity entity = response2.getEntity(); System.out.println("Login form get: " + response2.getStatusLine()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response2.close(); } } finally { httpclient.close(); } }
From source file:jdbc.ClientFormLogin.java
public static void main(String[] args) throws Exception { BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); java.net.CookieManager cm = new java.net.CookieManager(); java.net.CookieHandler.setDefault(cm); try {/*from w w w.j ava 2 s . c o m*/ HttpGet httpget = new HttpGet("http://www.cophieu68.vn/export/excel.php?id=AAA"); CloseableHttpResponse response1 = httpclient.execute(httpget); try { HttpEntity entity = response1.getEntity(); System.out.println("Login form get: " + response1.getStatusLine()); EntityUtils.consume(entity); System.out.println("Initial set of cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response1.close(); } HttpUriRequest login = RequestBuilder.post() .setUri(new URI("http://www.cophieu68.vn/export/excel.php?id=AAA")) .addParameter("username", "hello_nguyenson@live.com").addParameter("tpassword", "19931994") .build(); CloseableHttpResponse response2 = httpclient.execute(login); try { HttpEntity entity = response2.getEntity(); System.out.println("Login form get: " + response2.getStatusLine()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response2.close(); } } finally { httpclient.close(); } }
From source file:zz.pseas.ghost.login.weibo.WeibocnLogin.java
public static void main(String[] args) throws NullPointerException { // ?URL/*ww w . j av a 2 s . c o m*/ String Loginurl = "http://login.weibo.cn/login/"; String firstpage = "http://weibo.cn/?vt=4"; // ?? String loginnum = "test"; String loginpwd = "test"; CloseableHttpClient httpclient = HttpClients.createDefault(); // HttpGet httpget = new HttpGet(Loginurl); try { CloseableHttpResponse response = httpclient.execute(httpget); String responhtml = null; try { responhtml = EntityUtils.toString(response.getEntity()); // System.out.println(responhtml); } catch (IOException e1) { e1.printStackTrace(); } // vk?,splithtml,?? String vk = responhtml.split("<input type=\"hidden\" name=\"vk\" value=\"")[1].split("\" /><input")[0]; System.out.println(vk); String pass = vk.split("_")[0]; String finalpass = "password_" + pass; System.out.println(finalpass); response.close(); List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>(); pairs.add(new BasicNameValuePair("mobile", loginnum)); pairs.add(new BasicNameValuePair(finalpass, loginpwd)); pairs.add(new BasicNameValuePair("remember", "on")); pairs.add(new BasicNameValuePair("vk", vk)); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs, Consts.UTF_8); // HttpPost httppost = new HttpPost(Loginurl); httppost.setEntity(entity); // ??? CloseableHttpResponse response2 = httpclient.execute(httppost); System.out.println(response2.getStatusLine().toString()); httpclient.execute(httppost); // ? System.out.println("success"); HttpGet getinfo = new HttpGet("http://m.weibo.cn/p/100803?vt=4"); CloseableHttpResponse res; res = httpclient.execute(getinfo); System.out.println("??:"); // ?html System.out.println(EntityUtils.toString(res.getEntity())); res.close(); } catch (IOException e) { e.printStackTrace(); } finally { try { httpclient.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file: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 ava2 s .c o m*/ HttpGet httpget = new HttpGet("http://localhost/"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:demo.example.ClientWinAuth.java
public final static void main(String[] args) throws Exception { if (!WinHttpClients.isWinAuthAvailable()) { System.out.println("Integrated Win auth is not supported!!!"); }//from w ww. ja v a2 s . c o m CloseableHttpClient httpclient = WinHttpClients.createDefault(); // There is no need to provide user credentials // HttpClient will attempt to access current user security context through // Windows platform specific methods via JNI. try { HttpGet httpget = new HttpGet("http://winhost/"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:eu.transcriptorium.trpclient.ClientAuthentication.java
public static void main(String[] args) throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope("dbis-faxe.uibk.ac.at", 443), new UsernamePasswordCredentials(user, password)); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); try //Set-Cookie: JSESSIONID=ABAD1D;path=/ {//from www .ja v a2 s . c o m HttpGet httpget = new HttpGet("https://dbis-faxe.uibk.ac.at/TrpServerTesting/rest/docs/62/fulldoc.xml"); //httpclient. httpget.setHeader("Cookie", "JSESSIONID=5FB6AC0CD0F4FAC80CE6716DD789F5E8"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.lxf.spider.client.ClientExecuteProxy.java
public static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {//from ww w .ja v a 2 s .co m HttpHost target = new HttpHost("localhost", 443, "https"); HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http"); RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); HttpGet request = new HttpGet("/"); request.setConfig(config); System.out.println("Executing request " + request.getRequestLine() + " to " + target + " via " + proxy); CloseableHttpResponse response = httpclient.execute(target, request); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.guilhermehott.http_post_file.ClientMultipartFormPost.java
public static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {/* w ww.java 2 s . c o m*/ HttpPost httppost = new HttpPost("http://www.servidor2.danfeonline.com.br"); FileBody bin = new FileBody(new File("C:/Users/Guilherme/Downloads/CAMMINARE - NFE EM XML/teste.xml")); HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("bin", bin).build(); httppost.setEntity(reqEntity); System.out.println("executing request " + httppost.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httppost); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { System.out.println("Response content length: " + resEntity.getContentLength()); } EntityUtils.consume(resEntity); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:cn.anthony.util.ClientAuthentication.java
public static void main(String[] args) throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope("httpbin.org", 80), new UsernamePasswordCredentials("user", "passwd")); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); try {/*w w w . j av a 2s. com*/ HttpGet httpget = new HttpGet("http://httpbin.org/basic-auth/user/passwd"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); System.out.println(EntityUtils.toString(response.getEntity())); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.guilhermehott.http_post_file.ClientProxyAuthentication.java
public static void main(String[] args) throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope("proxybsb.cast.com.br", 3128), new UsernamePasswordCredentials("guilherme.hott@cast.com.br", "getOcwcd14")); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); try {//from w w w . ja va 2 s . com HttpHost target = new HttpHost("www.verisign.com", 443, "https"); HttpHost proxy = new HttpHost("proxybsb.cast.com.br", 3128); RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); HttpGet httpget = new HttpGet("/"); httpget.setConfig(config); System.out.println("Executing request " + httpget.getRequestLine() + " to " + target + " via " + proxy); CloseableHttpResponse response = httpclient.execute(target, httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); } finally { response.close(); } } finally { httpclient.close(); } }