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.
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.