File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error 405 with HttpUrlConnection when request web service

 
Oscar Calderon
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error 405 says.. Method not allowed.

You might be trying to call the post method.. on a "GET" resource.
 
Oscar Calderon
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20398
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you'll have more success in our web services forum. Moving there.
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could you please post the complete stack trace at client.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic