List of usage examples for org.apache.commons.httpclient.methods PostMethod PostMethod
public PostMethod(String paramString)
From source file:Correct.java
public static void main(String[] args) { String URLL = ""; HttpClient client = new HttpClient(); HttpMethod method = new PostMethod(URLL); method.setDoAuthentication(true);/*from w ww .j a v a2 s.co m*/ HostConfiguration hostConfig = client.getHostConfiguration(); hostConfig.setHost("172.29.38.8"); hostConfig.setProxy("172.29.90.4", 8); // NTCredentials proxyCredentials = new NTCredentials("", "", "", ""); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("", "")); //// try { //// URL url = new URL(""); //// HttpURLConnection urls = (HttpURLConnection) url.openConnection(); //// //// //// } catch (MalformedURLException ex) { //// Logger.getLogger(Correct.class.getName()).log(Level.SEVERE, null, ex); //// } catch (IOException ex) { //// Logger.getLogger(Correct.class.getName()).log(Level.SEVERE, null, ex); //// } try { // send the transaction client.executeMethod(hostConfig, method); StatusLine status = method.getStatusLine(); if (status != null && method.getStatusCode() == 200) { System.out.println(method.getResponseBodyAsString() + "\n Status code : " + status); } else { System.err.println(method.getStatusLine() + "\n: Posting Failed !"); } } catch (IOException ioe) { ioe.printStackTrace(); } method.releaseConnection(); }
From source file:com.fusesource.demo.controller.Client.java
public static void main(String args[]) throws Exception { Client client = new Client(); PostMethod post = new PostMethod("http://localhost:" + port + "/controller/process"); post.addRequestHeader("Accept", "text/xml"); RequestEntity entity = new StringRequestEntity(DATA, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE, null); post.setRequestEntity(entity);//from w w w . j a v a2s. c o m HttpClient httpclient = new HttpClient(); try { System.out.println("Sending data:\n" + DATA); int result = httpclient.executeMethod(post); System.out.println("Response status code: " + result); System.out.println("Response body: "); System.out.println("Response data:\n" + post.getResponseBodyAsString()); } finally { post.releaseConnection(); } System.out.println("\n"); System.exit(0); }
From source file:com.manning.blogapps.chapter10.examples.AuthPost.java
public static void main(String[] args) throws Exception { if (args.length < 4) { System.out.println("USAGE: authpost <username> <password> <filepath> <url>"); System.exit(-1);/*from w w w .jav a2s .co m*/ } String credentials = args[0] + ":" + args[1]; String filepath = args[2]; String url = args[3]; HttpClient httpClient = new HttpClient(); EntityEnclosingMethod method = new PostMethod(url); method.setRequestHeader("Authorization", "Basic " + new String(Base64.encodeBase64(credentials.getBytes()))); File upload = new File(filepath); method.setRequestHeader("Title", upload.getName()); method.setRequestBody(new FileInputStream(upload)); String contentType = "application/atom+xml; charset=utf8"; if (filepath.endsWith(".gif")) contentType = "image/gif"; else if (filepath.endsWith(".jpg")) contentType = "image/jpg"; method.setRequestHeader("Content-type", contentType); httpClient.executeMethod(method); System.out.println(method.getResponseBodyAsString()); }
From source file:com.chiral.oauth.OAuthLoginUtil.java
public static void main(String[] args) throws Exception { // Step 0: Connect to SalesForce. OAuthConfiguration config;//www. j a v a 2s . com File configFile = new File(args[0]); config = OAuthConfiguration.fromYaml(new FileInputStream(configFile)); System.out.println("Getting a token"); String tokenUrl = config.environment + "/services/oauth2/token"; //TODO hparry use JAX-RS instead of Apache commons HttpClient httpclient = new HttpClient(); PostMethod post = new PostMethod(tokenUrl); post.addParameter("grant_type", "password"); post.addParameter("client_id", config.clientId); post.addParameter("client_secret", config.secret); post.addParameter("redirect_uri", config.redirectUri); post.addParameter("username", config.username); post.addParameter("password", config.password); try { httpclient.executeMethod(post); System.out.println(post.getResponseBodyAsString()); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { post.releaseConnection(); } }
From source file:com.leixl.easyframework.action.httpclient.TestHttpPost.java
public static void main(String[] args) { Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("uid", 1); paramMap.put("desc", "?????"); paramMap.put("payStatus", 1); //HttpConnUtils.postHttpContent(URL, paramMap); //HttpClient// w w w . j a v a 2 s . co m HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod(URL); // ?? NameValuePair[] data = { new NameValuePair("uid", "1"), new NameValuePair("desc", "?????"), new NameValuePair("payStatus", "1") }; // ?postMethod postMethod.setRequestBody(data); // postMethod int statusCode; try { statusCode = httpClient.executeMethod(postMethod); if (statusCode == HttpStatus.SC_OK) { StringBuffer contentBuffer = new StringBuffer(); InputStream in = postMethod.getResponseBodyAsStream(); BufferedReader reader = new BufferedReader( new InputStreamReader(in, postMethod.getResponseCharSet())); String inputLine = null; while ((inputLine = reader.readLine()) != null) { contentBuffer.append(inputLine); System.out.println("input line:" + inputLine); contentBuffer.append("/n"); } in.close(); } else if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) { // ??? Header locationHeader = postMethod.getResponseHeader("location"); String location = null; if (locationHeader != null) { location = locationHeader.getValue(); System.out.println("The page was redirected to:" + location); } else { System.err.println("Location field value is null."); } } } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.discursive.jccook.httpclient.PostFileExample.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(); // Create POST method String weblintURL = "http://ats.nist.gov/cgi-bin/cgi.tcl/echo.cgi"; PostMethod method = new PostMethod(weblintURL); File file = new File("project.xml"); method.setRequestBody(new FileInputStream(file)); method.setRequestContentLength((long) file.length()); // Execute and print response client.executeMethod(method);//ww w .j av a 2 s . c o m String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); }
From source file:com.discursive.jccook.httpclient.PostExample.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(); // Create POST method String weblintURL = "http://www.discursive.com/cgi-bin/jccook/param_list.cgi"; PostMethod method = new PostMethod(weblintURL); // Set parameters on POST method.setParameter("test1", "Hello World"); method.addParameter("test2", "This is a Form Submission"); method.addParameter("Blah", "Whoop"); method.addParameter(new NameValuePair("Blah", "Whoop2")); // Execute and print response client.executeMethod(method);/* w w w. ja v a2s .c o m*/ String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); }
From source file:TestCookieDecode.java
/** * @param args//from w w w . ja v a2 s. c o m */ public static void main(String[] args) throws Exception { // // TODO Auto-generated method stub // DefaultCryptoBeanDefinition() blowfishCrypto = new // DefaultCryptoBeanDefinition(); // blowfishCrypto.setAlgorithm("Blowfish"); // blowfishCrypto.setTransformation("Blowfish/CBC/NoPadding"); // blowfishCrypto.setKey(cryptoKey); // blowfishCrypto.setProvider("CryptixCrypto"); // // java.security.Security.addProvider(new // cryptix.jce.provider.CryptixCrypto()); // String key="^#16qweqv88cde729!@#$3450abfg^%"; // SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), // "Blowfish"); // Cipher deCipher = // Cipher.getInstance("Blowfish/CBC/NoPadding","CryptixCrypto"); // deCipher.init(Cipher.DECRYPT_MODE, secretKey); // byte[] ret= deCipher.doFinal( // Base64Util.decode("ihxD3imKsk724mCURZhHkD3QbIzWcXp3NbZBi72ilN9td+XSaN5nYUH1N7JwXKMj")); // System.out.println(new String(ret).substring(8).trim()); HttpClient client = new HttpClient(); client.getHostConfiguration().setHost("www.guahao.com", 80); PostMethod post = new PostMethod("/outSysGetUserCookieValue"); NameValuePair name = new NameValuePair("signdata", "PjPQvzc6j1UOmThSb3IUkw=="); NameValuePair pass = new NameValuePair("cookieValue", "{\"__uli__\":\"sDZXBw9ZZm/QM3lksxZ7mVjUFIbpup7//oPTueSeWY1XhNAQhIPSPiPFV5EqKMoO3qeJSLoBdt3LxwvuTUSW9g==\"}"); post.setRequestBody(new NameValuePair[] { name, pass }); client.executeMethod(post); System.out.println(post.getResponseBodyAsString()); post.releaseConnection(); String signdata = DESUtils.dCode("Py8o3huCfMcSJR4HBjDe0w==", EncodeKeyConstants.OUT_SYS_USER_KEY); System.out.println(signdata); }
From source file:UnbufferedPost.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("Usage: ChunkEncodedPost <file>"); System.out.println("<file> - full path to a file to be posted"); System.exit(1);// w w w . j a v a 2 s.c o m } HttpClient client = new HttpClient(); PostMethod httppost = new PostMethod("http://localhost:8080/httpclienttest/body"); File file = new File(args[0]); httppost.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(file), file.length())); try { client.executeMethod(httppost); if (httppost.getStatusCode() == HttpStatus.SC_OK) { System.out.println(httppost.getResponseBodyAsString()); } else { System.out.println("Unexpected failure: " + httppost.getStatusLine().toString()); } } finally { httppost.releaseConnection(); } }
From source file:ChunkEncodedPost.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("Usage: ChunkEncodedPost <file>"); System.out.println("<file> - full path to a file to be posted"); System.exit(1);//from w ww .ja v a2 s .c om } HttpClient client = new HttpClient(); PostMethod httppost = new PostMethod("http://localhost:8080/httpclienttest/body"); File file = new File(args[0]); httppost.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(file))); httppost.setContentChunked(true); try { client.executeMethod(httppost); if (httppost.getStatusCode() == HttpStatus.SC_OK) { System.out.println(httppost.getResponseBodyAsString()); } else { System.out.println("Unexpected failure: " + httppost.getStatusLine().toString()); } } finally { httppost.releaseConnection(); } }