dcsimg
How do I send "post" request to Servlet via URLConnection
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nitimate_Kasemsook
Posted On:   Monday, April 28, 2003 01:50 AM

How do I send post method request to Servlet via URLConnection.I've tried to get OutputStream from URLConnection,that connect to Servlet but It doesn't get the OutputStream.I'm using apache-tomcat-3.3.1 as Web Server.When I had started my application.It posted this message "2003-04-28 09:58:00 - Http10Interceptor: SocketException reading request, ignored" at the tomcat 's console when i tried to get outputstream by URLConnection.getOutputStream();. // prepare connection URL url = new URL("Servlet 's URL"); URLConnection urlConnection = url.openConnection(); urlConnection.setDoInput(true); urlConnection.setUseCaches(false); urlConnection.setDoOutput(true); urlConnection.setReq   More>>

How do I send post method request to Servlet via URLConnection.I've tried to get OutputStream from URLConnection,that connect to Servlet but It doesn't get the OutputStream.I'm using apache-tomcat-3.3.1 as Web Server.When I had started my application.It posted this message "2003-04-28 09:58:00 - Http10Interceptor: SocketException reading request, ignored" at the tomcat 's console when i tried to get outputstream by URLConnection.getOutputStream();.


// prepare connection

URL url = new URL("Servlet 's URL");
URLConnection urlConnection = url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
urlConnection.setRequestProperty("Accept-Language", "th,en-us;q=0.5");

// send data if it has
try {
OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());
out.write("?param=test");
out.close();
} catch (IOException e) {

e.printStackTrace();

}

When I comment getOutputStream line.It doesn't post any error at tomcat's console.Can anybody help me.

   <<Less

Re: How do I send "post" request to Servlet via URLConnection

Posted By:   Stephen_McConnell  
Posted On:   Monday, April 28, 2003 05:19 AM

Have you used HtppURLConnection?


It is a subclass of URLConnection with provisions for setting request header information and interpreting header info.


I don't see anything wrong with your code (although it would be nice if you would use

</pre> tags around your code to make it more readable).   Are you calling this servlet from the same server instance that the servlet is in?  Is your URL correct?


Stephen McConnell

About | Sitemap | Contact