Next problem: HttpURLConnection

D

Donkey Hottie

Following code does not connect

URL url = new URL("http://localhost:8090/myapp/logger");
URLConnection connection = url.openConnection();
logger.finest("[url class: " + connection.getClass().getName() + "]") ;
connection.setDoInput(false);
connection.setDoOutput(true);
connection.setAllowUserInteraction(false);
((HttpURLConnection) connection).setRequestMethod("POST");
connection.connect() ;
OutputStreamWriter outstream = new OutputStreamWriter
(connection.getOutputStream(), getEncoding()) ;
outstream.write("message=" + output) ;
outstream.flush();
outstream.close();
logger.finest("[Sent a message]") ;

Logger logs as follows:

6.10.2008 18:10:39 (http-0.0.0.0-8090-Processor25)
[MyHTTPHandler] publish FINEST - [entering,
url=http://localhost:8090/myapp/logger]

6.10.2008 18:10:39 (http-0.0.0.0-8090-Processor25)
[MyHTTPHandler] publish FINEST - [url class:
sun.net.www.protocol.http.HttpURLConnection]

6.10.2008 18:10:40 (http-0.0.0.0-8090-Processor25)
[MyHTTPHandler] publish FINEST - [Sent a message]

So, it flows the code thru, and tells everything went fine. Even if I give
an invalid URL to it! No exceptions, no errors.

When I enter the URL to a browser, the servlet there responds and works
fine. But it never sees this client code.

Any ideas?

This is running on J2EE 1.4.2 on a JBoss server.
 
D

Donkey Hottie

Following code does not connect

Never mind. The problem was apparently setDoInput(false).

Seems it have to be true, no matter if I want input or not. And actually I
want, I want the reponse code, and that can't be get if that is false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,730
Latest member
AudryNolan

Latest Threads

Top