Forums Register Login

sending PUT,DELETE requests to HttpServlet (urgent)

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2092 times.
Similar Threads
POSTing from applet to servlet
Cookies from Servlets sendRedirect
File Download from URL that required posting of URL paramter.
Error 405 with HttpUrlConnection when request web service
Two questions
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 21:24:37.