wood burning stoves 2.0*
The moose likes Web Services and the fly likes Error 405 with HttpUrlConnection when request web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Error 405 with HttpUrlConnection when request web service" Watch "Error 405 with HttpUrlConnection when request web service" New topic
Author

Error 405 with HttpUrlConnection when request web service

Oscar Calderon
Ranch Hand

Joined: Nov 27, 2009
Posts: 32
Hi, first of all sorry if this isn't the appropiated thread to post my problem but i think if my problem is about http request this could be the right thread.

I have developed RESTful web services, to consume this service you do via HTTP requests, that can be GET, POST, PUT, DELETE and so on, mapped to methods defined in web service. Now i'm developing a simple java application to consume this services. I've found that i can use the object HttpURLConnection to do HTTP requests and specify the method that i wanna use, in my case i want to do a POST request. The code of my application is this:



Is a simple java application without gui. When i run it, i get this message:

Exception in thread "main" java.io.IOException: Server returned HTTP response code: 405 for URL: ....
at java.net.URL.openStream

I can't understand why it doesn't admit the request even when i specify the protocol.

Wanna grow? Learn, live, love people and enjoy life
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Error 405 says.. Method not allowed.

You might be trying to call the post method.. on a "GET" resource.


- Chinna
Oscar Calderon
Ranch Hand

Joined: Nov 27, 2009
Posts: 32
Well, i couldn't read the forum because a problem, but in reply to you Chinna Eranna, my RESTful Web service has a POST resource, i've checked it. I tested my application consuming a GET resource and i have no problem, the application consumes the resource very well, but when i change the resource to POST and my application specifying the POST protocol, it fails.

I don't know if this is important, but here's my RESTful web service:



The GET resource that is commented works very well, while POST resource can't be consumed from my java application.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

I think you'll have more success in our web services forum. Moving there.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

could you please post the complete stack trace at client.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error 405 with HttpUrlConnection when request web service