Hi ,
Sending a POST request to a server/servlet you have to write the POST data .
So your commented code should be uncommented first . You were doing right .
You have to do one more thing ie. conn.setRequestMethod("POST");


-----------------------
Sujoy ,
eGain Communications Corporation , CA
-----------------------
Don't speak unless you can improve on the silence.

----- Original Message -----
From: 200540-Shaji Balakrishnan <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, December 06, 2000 6:40 PM
Subject: URLConnection problem


> Hi,
>
> I need to have a method which opens a connection to a servlet, posts some
> data, and reads the output. I wrote the following code in that method.
>
> // Method
> String strUrl = "http://localhost:8080/servlet/MyServlet";
> String strQuery = "i1="  + URLEncoder.encode("420");
>
> URL url = new URL(strUrl + "?" + strQuery);
> URLConnection connection = url.openConnection();
> connection.setDoInput(true);
> connection.setDoOutput(true);
> connection.setAllowUserInteraction(false);
>
> /* Commented out
> DataOutputStream output = new
> DataOutputStream(connection.getOutputStream());
> output.writeBytes(strQuery);
> output.close();
> */
>
> // Read in the response
> BufferedReader input = new BufferedReader(new
> InputStreamReader(connection.getInputStream()));
>
> file://Continue processing.....
> // End of method
>
> In MyServlet servlet when I say request.getParameter(i1) I seem to get a
> null value.
> However when I uncomment the commented lines of code, it works!
>
> Does anyone know the reason?. I use VAJ 3.02 with Websphere test
> environment.
>
> Thanks
> Shaji B
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to