List of usage examples for org.apache.commons.httpclient HttpMethod getResponseBodyAsString
public abstract String getResponseBodyAsString() throws IOException;
From source file:com.discursive.jccook.httpclient.SSLExample.java
public static void main(String[] args) throws HttpException, IOException { HttpClient client = new HttpClient(); String url = "https://www.amazon.com/gp/flex/sign-in.html"; HttpMethod method = new GetMethod(url); client.executeMethod(method);//w w w . j a va 2 s .com String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); method.recycle(); }
From source file:com.discursive.jccook.httpclient.CustomSSLExample.java
public static void main(String[] args) throws HttpException, IOException { HttpClient client = new HttpClient(); String url = "https://pericles.symbiont.net/jccook"; ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); Protocol https = new Protocol("https", socketFactory, 443); Protocol.registerProtocol("https", https); HttpMethod method = new GetMethod(url); client.executeMethod(method);/* ww w.j a va 2 s . com*/ String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); method.recycle(); }
From source file:com.discursive.jccook.httpclient.NTLMAuthExample.java
public static void main(String[] args) throws HttpException, IOException { HttpClient client = new HttpClient(); // Set credentials on the client Credentials credentials = new NTCredentials("testuser", "crazypass", "tobrien.discursive.com", "DOMAIN"); client.getState().setCredentials(null, null, credentials); String url = "http://webmail.domain.biz/exchange/"; HttpMethod method = new GetMethod(url); client.executeMethod(method);// w w w . j a v a 2 s . c o m String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); }
From source file:com.discursive.jccook.httpclient.DebuggingExample.java
public static void main(String[] args) throws HttpException, IOException { // Configure Logging System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); HttpClient client = new HttpClient(); String url = "http://www.discursive.com/jccook/"; HttpMethod method = new GetMethod(url); client.executeMethod(method);//from w w w . ja v a2s . co m String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); method.recycle(); }
From source file:com.discursive.jccook.httpclient.BasicAuthExample.java
public static void main(String[] args) throws HttpException, IOException { // Configure Logging System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); HttpClient client = new HttpClient(); HttpState state = client.getState(); HttpClientParams params = client.getParams(); // Set credentials on the client Credentials credentials = new UsernamePasswordCredentials("testuser", "crazypass"); state.setCredentials(null, null, credentials); params.setAuthenticationPreemptive(true); String url = "http://www.discursive.com/jccook/auth/"; HttpMethod method = new GetMethod(url); client.executeMethod(method);//ww w . j a v a2 s. c o m String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); }
From source file:com.discursive.jccook.httpclient.GetExample.java
public static void main(String[] args) { HttpClient client = new HttpClient(); String url = "http://www.discursive.com/jccook/"; HttpMethod method = new GetMethod(url); try {/* w w w . ja v a 2 s . c om*/ client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (HttpException he) { System.out.println("HTTP Problem: " + he.getMessage()); } catch (IOException ioe) { System.out.println("IO Exeception: " + ioe.getMessage()); } finally { method.releaseConnection(); method.recycle(); } }
From source file:com.discursive.jccook.httpclient.QueryStringExample.java
public static void main(String[] args) throws HttpException, IOException { HttpClient client = new HttpClient(); String url = "http://www.discursive.com/cgi-bin/jccook/param_list.cgi"; // Set the Query String with setQueryString() HttpMethod method = new GetMethod(url); method.setQueryString(URIUtil.encodeQuery("test1=O'Reilly&blah=Whoop")); System.out.println("With Query String: " + method.getURI()); client.executeMethod(method);/* w w w. j a v a2 s .c om*/ System.out.println("Response:\n " + method.getResponseBodyAsString()); method.releaseConnection(); // Set query string with name value pair objects method = new GetMethod(url); NameValuePair pair = new NameValuePair("test2", URIUtil.encodeQuery("One & Two")); NameValuePair pair2 = new NameValuePair("param2", URIUtil.encodeQuery("TSCM")); NameValuePair[] pairs = new NameValuePair[] { pair, pair2 }; method.setQueryString(pairs); System.out.println("With NameValuePairs: " + method.getURI()); client.executeMethod(method); System.out.println("Response:\n " + method.getResponseBodyAsString()); method.releaseConnection(); }
From source file:com.ebay.recommendations.LatestVersion.java
/** * @param args/* www . j av a2 s. c o m*/ */ public static void main(String[] args) { // TODO Auto-generated method stub HttpClient client = new HttpClient(); String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/latestVersion"; HttpMethod method = new GetMethod(fullUri); // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>"); method.addRequestHeader("Accept", "application/xml"); try { client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ebay.recommendations.ItemRecommendations.java
/** * @param args// w ww. ja v a 2s .co m */ public static void main(String[] args) { HttpClient client = new HttpClient(); String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/v1/item/300878655630/itemRecommendations/"; HttpMethod method = new GetMethod(fullUri); // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>"); method.addRequestHeader("X-EBAY-GLOBAL-ID", "EBAY-US"); method.addRequestHeader("Accept", "application/xml"); try { client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ebay.recommendations.RecommendationItemIds.java
/** * @param args/*from w ww.j a v a 2 s.co m*/ */ public static void main(String[] args) { // TODO Auto-generated method stub HttpClient client = new HttpClient(); String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/v1/item/recommendationItemIds?recommendationType=Picture&pageNumber=1&entriesPerPage=5"; HttpMethod method = new GetMethod(fullUri); // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>"); method.addRequestHeader("X-EBAY-GLOBAL-ID", "EBAY-US"); method.addRequestHeader("Accept", "application/xml"); try { client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } }