File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Error 405 with getOutputStream() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error 405 with getOutputStream()" Watch "Error 405 with getOutputStream()" New topic

Error 405 with getOutputStream()

Mike Rybicki

Joined: Apr 12, 2006
Posts: 2
I am writing an app, using JRun, that will do the following:

1. Receive a POST from an external IP
2. Parse the parameters, one being the external IP address, and fire a POST request for more data
3. Receive a second POST from the IP with the extra data

For now, I am testing with a Perl script that fires off a POST, receives the request from the app, and
sends the second POST.

Below is the code section:


URL u=null;
HttpURLConnection conn=null;
OutputStream theOutStream=null;
InputStream theInStream=null;

u = new URL(url);
conn=(HttpURLConnection) u.openConnection();


int rc = conn.getResponseCode();
if( DEBUG ) LOG_INFO("** rc: "+rc);
String rval = conn.getResponseMessage();
SK_Servlet.LOG_INFO("** rval: " + rval);

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theOutStream));

StringBuffer startupParams = new StringBuffer();
theInStream = conn.getInputStream();

BufferedReader in = new BufferedReader(new InputStreamReader(theInStream));


The Perl script runs and sends the first POST. The app receives the POST and parses it, but when I send my POST,
it errors. I get in the log:

04/12 09:20:58 info ** rc: 405
04/12 09:20:58 info ** rval: Method Not Allowed

I tried adding conn.connect() before making the getOutputStream() call, but I get the same error.

Any tips/suggestions would be greatly appreciated. Thanks.

Just say WOOF.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63534

This error usually occurs when a servlet (or other server-side target) isn't wired up to accept the HTTP method type -- for example, not implementing doPost() in a servlet.

Is the target of this post set up to accept POST operations?

[Asking smart questions] [About Bear] [Books by Bear]
Mike Rybicki

Joined: Apr 12, 2006
Posts: 2
The client app will be. The test machine I am using is a linux box with Perl. The linux box is receiving without any problem. We won't have access to the true client for a couple weeks.

If this is the issue, then I will "code around" and wait until I have access to their client to verify the connection.

Thank you.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63534

Cool. Check back if you have further problems when connecting to the actual client.
I agree. Here's the link:
subject: Error 405 with getOutputStream()
It's not a secret anymore!