1 31 32 import java.io.File ; 33 34 import org.apache.commons.httpclient.HttpClient; 35 import org.apache.commons.httpclient.methods.FileRequestEntity; 36 import org.apache.commons.httpclient.methods.PostMethod; 37 import org.apache.commons.httpclient.methods.RequestEntity; 38 39 51 public class PostXML { 52 53 63 public static void main(String [] args) throws Exception { 64 if (args.length != 2) { 65 System.out.println("Usage: java -classpath <classpath> [-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>] PostXML <url> <filename>]"); 66 System.out.println("<classpath> - must contain the commons-httpclient.jar and commons-logging.jar"); 67 System.out.println("<loglevel> - one of error, warn, info, debug, trace"); 68 System.out.println("<url> - the URL to post the file to"); 69 System.out.println("<filename> - file to post to the URL"); 70 System.out.println(); 71 System.exit(1); 72 } 73 String strURL = args[0]; 75 String strXMLFilename = args[1]; 77 File input = new File (strXMLFilename); 78 PostMethod post = new PostMethod(strURL); 80 RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); 83 post.setRequestEntity(entity); 84 HttpClient httpclient = new HttpClient(); 86 try { 88 int result = httpclient.executeMethod(post); 89 System.out.println("Response status code: " + result); 91 System.out.println("Response body: "); 93 System.out.println(post.getResponseBodyAsString()); 94 } finally { 95 post.releaseConnection(); 97 } 98 } 99 } 100 | Popular Tags |