List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:HttpClientTest.java
public static void main(String args[]) throws Exception { HttpClient client = new HttpClient(); GetMethod method = new GetMethod("http://www.google.com"); int returnCode = client.executeMethod(method); System.err.println(method.getResponseBodyAsString()); method.releaseConnection();/* w w w . j a va 2 s. c om*/ }
From source file:GetCookiePrintAndSetValue.java
public static void main(String args[]) throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "My Browser"); GetMethod method = new GetMethod("http://localhost:8080/"); try {// ww w .java2s .c o m client.executeMethod(method); Cookie[] cookies = client.getState().getCookies(); for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; System.err.println("Cookie: " + cookie.getName() + ", Value: " + cookie.getValue() + ", IsPersistent?: " + cookie.isPersistent() + ", Expiry Date: " + cookie.getExpiryDate() + ", Comment: " + cookie.getComment()); cookie.setValue("My own value"); } client.executeMethod(method); } catch (Exception e) { System.err.println(e); } finally { method.releaseConnection(); } }
From source file:HttpClientParameter.java
public static void main(String args[]) throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "My Browser"); HostConfiguration host = client.getHostConfiguration(); host.setHost("www.google.com"); GetMethod method = new GetMethod("http://www.yahoo.com"); int returnCode = client.executeMethod(host, method); System.err.println(method.getResponseBodyAsString()); System.err//w ww . j a v a2s. co m .println("User-Agent: " + method.getHostConfiguration().getParams().getParameter("http.useragent")); System.err.println("User-Agent: " + method.getParams().getParameter("http.useragent")); method.releaseConnection(); }
From source file:BasicAuthenticationExecuteJSPMethod.java
public static void main(String args[]) throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter("parameterKey", "value"); HostConfiguration host = client.getHostConfiguration(); host.setHost(new URI("http://localhost:8080", true)); GetMethod method = new GetMethod("/commons/folder/protected.jsp"); try {/* w w w. ja v a2s . c o m*/ client.executeMethod(host, method); System.err.println(method.getStatusLine()); System.err.println(method.getResponseBodyAsString()); } catch (Exception e) { System.err.println(e); } finally { method.releaseConnection(); } }
From source file:com.ebay.recommendations.ItemRecommendations.java
/** * @param args/*from ww w . j a v a 2 s .c o 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.LatestVersion.java
/** * @param args/*from ww w . j a v a 2 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:HttpClientPreferences.java
public static void main(String args[]) throws Exception { HttpClient client = new HttpClient(); System.err.println(/*w w w. j av a 2s . com*/ "The User Agent before changing it is: " + client.getParams().getParameter("http.useragent")); client.getParams().setParameter("http.useragent", "Browser at Client level"); System.err.println("Client's User Agent is: " + client.getParams().getParameter("http.useragent")); GetMethod method = new GetMethod("http://www.google.com"); method.getParams().setParameter("http.useragent", "Browser at Method level"); try { client.executeMethod(method); } catch (Exception e) { System.err.println(e); } finally { method.releaseConnection(); } System.err.println("Method's User Agent is: " + method.getParams().getParameter("http.useragent")); }
From source file:com.ebay.recommendations.RecommendationsSummary.java
/** * @param args/*from w w w . ja v 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/v1/item/recommendationsSummary"; 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 w w . j ava 2s. 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/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(); } }
From source file:com.blueferdi.diamondbox.jetty.connector.HttpClientDemo.java
public static void main(String[] args) throws IOException { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setSoTimeout(1); int i = 1000; while (i > 0) { try {//from w w w.j a v a 2 s . c om GetMethod method = new GetMethod("http://localhost:8080/testblocking/BlockingServlet"); method.setRequestHeader("Connection", "close"); client.executeMethod(method); } catch (Exception ex) { i--; System.out.println(i); } } }