Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JSP Interest »

How to Use HTTP POST in standalone code

[Kiran Kumar Vedula]

2006-05-10


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)".
For digest: mailto listserv@(protected)".

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
©2008 junlu.com - Jax Systems, LLC, U.S.A.