  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | How to Use HTTP POST in standalone code | How to Use HTTP POST in standalone code 2006-05-10 - By [Kiran Kumar Vedula]
Back I am able to get the Server Response from a standalone code by passing parameters appended to a URL, in a way it can be said Get method.I am not clear how to use Post for the same, cos The Url length has a limitation in processing the request.Any inputs will be of great help.
Please find the code below using URL to send the request.
import java.io.* ; import java.net.* ; import java.security.* ; import java.util.* ;
class test{
public static void main(String [] args){ String inputfilename=""; String strLine=""; String strVar=""; int counter, numberOfTokens = 0; inputfilename=args[0]; try { FileReader inputFileReaderdump = new FileReader(inputfilename); BufferedReader inputFile = new BufferedReader(inputFileReaderdump); while ((strLine = inputFile.readLine()) != null) { StringTokenizer strTokLine = new StringTokenizer(strLine, ","); numberOfTokens = strTokLine.countTokens(); String XXX_URL="http://darkwing.brocade.com:8080/DEVPGC/JSP/PGACMultiItemReport.js p?BPN=BPN&itemNumbers="+strLine; URL url = new URL(XXX_URL) ; URLConnection urlc = url.openConnection() ; urlc.setDoOutput(true); urlc.setDoInput(true); BufferedReader br = new BufferedReader(new InputStreamReader (urlc.getInputStream())) ; String responseXml = "" ; String s = null ; while ((s = br.readLine()) != null){ responseXml += s ; } System.out.println("[RESPONSE] " + responseXml) ; } }catch(Exception e){System.out.println(e.getMessage()); }
}
}
=========================================================================== To unsubscribe: mailto listserv@(protected) with body: "signoff JSP-INTEREST". For digest: mailto listserv@(protected) with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
|
|
 |