I am not sure but why not try to add in the following statement:
connection.setDoInput(true);
???
liwen
----- Original Message -----
From: "Nash, Corey" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 30, 2000 4:14 AM
Subject: [SERVLET-INTEREST] POSTing in a servlet
> Hi, all. I know this has been touched on in the past, but I couldn't find
> anything in the archives addressing this question. Does anyone know why,
> when I execute the first chunk of code below in a java application, it
works
> fine - all data is posted correctly; but when I execute the second chunk
of
> code below in a java servlet, it does not work? EchoServlet simply prints
> the request method, GET or POST that was used, as well as all data passed.
> When I ran the second chunk of code from the servlet, EchoServlet told me
> that the method was POST, but that no data was posted. Anyone have any
> ideas?
>
>
> --------------------------- Application code ---------------------------
> URL url = new URL("http://www.myserver.com/servlet/EchoServlet");
> URLConnection connection = url.openConnection();
> connection.setDoOutput(true);
>
> PrintStream outStream = new PrintStream(connection.getOutputStream());
> outStream.println("user=fred&password=flintstone&company=slate");
> outStream.close();
>
> BufferedReader inStream = new BufferedReader(new
>
> InputStreamReader(connection.getInputStream()));
>
> String inputLine;
> while ((inputLine = inStream.readLine()) != null) {
> System.out.println(inputLine);
> }
> inStream.close();
> ---------------------------------------------------------------------
>
>
> --------------------------- Servlet code ---------------------------
> PrintWriter pw = bucket.response.getWriter();
> pw.write("returned data:<HR>");
> URL url = new URL("http://www.myserver.com/servlet/EchoServlet");
> URLConnection connection = url.openConnection();
> connection.setDoOutput(true);
> PrintStream outStream = new PrintStream(connection.getOutputStream());
> outStream.println("user=fred&password=flintstone&company=slate");
> outStream.close();
> BufferedReader inStream = new BufferedReader(new
>
> InputStreamReader(connection.getInputStream()));
> String inputLine;
> while((inputLine = inStream.readLine()) != null) {
> pw.write(inputLine);
> }
> inStream.close();
>
> pw.write("<HR>end of returned data");
> ---------------------------------------------------------------------
>
> Thanks,
>
> --Corey Nash.
>
>
___________________________________________________________________________
> 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