List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:BasicAuthenticationForJSPPage.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(new URI("http://localhost:8080", true)); Credentials credentials = new UsernamePasswordCredentials("tomcat", "tomcat"); AuthScope authScope = new AuthScope(host.getHost(), host.getPort()); HttpState state = client.getState(); state.setCredentials(authScope, credentials); GetMethod method = new GetMethod("/commons/chapter01/protected.jsp"); try {/* www . j a v a 2s . co 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.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 {/*from w w w .j a v a2 s. c o m*/ 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.manning.blogapps.chapter10.examples.AuthGet.java
public static void main(String[] args) throws Exception { if (args.length < 3) { System.out.println("USAGE: authget <username> <password> <url>"); System.exit(-1);//from w ww . j a v a2 s.co m } String credentials = args[0] + ":" + args[1]; String url = args[2]; HttpClient httpClient = new HttpClient(); GetMethod method = new GetMethod(url); method.setRequestHeader("Authorization", "Basic " + new String(Base64.encodeBase64(credentials.getBytes()))); httpClient.executeMethod(method); System.out.println(method.getResponseBodyAsString()); }
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 av a2s .c om*/ String response = method.getResponseBodyAsString(); System.out.println(response); 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);//from ww w . j a v a 2 s . co m 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.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);// www. j a v a 2s . c om String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); }
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);//from ww w. jav a 2s.c om String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); method.recycle(); }
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 ww w. j a va2s. c om String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); method.recycle(); }
From source file:com.discursive.jccook.httpclient.RedirectExample.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/cgi-bin/jccook/redirect.cgi"; System.out.println("Executing Method not following redirects: "); HttpMethod method = new GetMethod(url); method.setFollowRedirects(false);//from w w w .j a va2s .c o m executeMethod(client, method); System.out.println("Executing Method following redirects: "); method = new GetMethod(url); method.setFollowRedirects(true); executeMethod(client, method); }
From source file:de.mpg.escidoc.services.edoc.CreatePurgeScript.java
/** * @param args/*from ww w . ja v a 2s . c o m*/ */ public static void main(String[] args) throws Exception { CORESERVICES_URL = PropertyReader.getProperty("escidoc.framework_access.framework.url"); logger.info("Querying core-services..."); HttpClient httpClient = new HttpClient(); GetMethod getMethod = new GetMethod(CORESERVICES_URL + "/srw/search/escidoc_all?maximumRecords=10000&query=escidoc.context.objid=" + IMPORT_CONTEXT); ProxyHelper.executeMethod(httpClient, getMethod); String response = getMethod.getResponseBodyAsString(); logger.info("...done!"); //System.out.println(response); logger.info("Transforming result..."); XSLTTransform transform = new XSLTTransform(); File stylesheet = new File("src/main/resources/itemlist2purgescript.xslt"); FileOutputStream outputStream = new FileOutputStream("purge.sh"); transform.transform(response, stylesheet, outputStream); logger.info("...done!"); logger.info("Finished!"); }