Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sending PUT,DELETE requests to HttpServlet (urgent)  RSS feed

 
Harun Hasdal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to use HttpUrlConnection in a client applet to send requests to server. But my HttpServlet didn't run any of the overriden doGet(),doPost(),doPUT() or doDelete() methods. I think it didn't get the incoming bytes as an http request.
This was my code for sending requests. I could not see any problems but maybe you will.

Question:
how can i send requests to a servlet as an html form sends post and put requests. is there any other way than HttpUrlConnection.
Can anyone show me a way for this?
Thanks.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a lot that can go wrong here.
First, you should make sure that the URL is valid by opening it with a browser.
Next, if you read the documentation for URLConnection, you'll see that the way you use the class (and subclass HTTPUrlConnection) is that you manipulate the parameters, connect to the server then receive the resource. Your code connects, then attempts to manipulate the request. Not good.
Next, you aren't encoding the request parameters. Since a URL cannot contain characters that are considered control characters (spaces for one) you must encode the parameters. URLEncoder is provided for just this purpose.
Finally, you need to close your output stream. The request to the server isn't complete until you do.
Have a look at this example and see if you can get it working for you.
 
Harun Hasdal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply

The URL is valid and true and no problem with encoding i have done it in setRequestParameters() method referenced in the above code.

I could not exactly understand what you mentioned about first manipulating parameters than connecting to server but im working on it.

i closed the output stream but again saw no action on the server side.

thanks again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!