URLconnection is a post by default and to your question just use a basic html form and in your action set it to post Hope that helps Ray Smilgius ------------------ Sun Certified Java Programmer Sun Certified Java Developer I-Net Certified A+ Certified Network+ Certified MCP
hi , Thanks for the reply . Can you also let me know if its possible to make a 'GET' request through the URLConnection ? Anirban
Joined: Jan 29, 2001
Just make the request from your browser and put the url connection in the doGet() method of the servlet and that will do a request to the server. ------------------ Sun Certified Java Programmer Sun Certified Java Developer I-Net Certified A+ Certified Network+ Certified MCP
Joined: Feb 06, 2001
Hi , I am sorry , I might not have explained the situation properly . I needed to make either a GET or a POST request from a application to a set of servlets .These servlets were designed badly by God-knows-who.They either have a doGet() or a doPost() method , but not both . A browser never comes into picture at all . From the application , I neet to make an URLConnection , and read/post data to these servlets by making either a GET or a POST request . Can you help me out ? Thanks Anirban
It's not uncommon for a servlet to be written so that doGet() invokes doPost(), making the request type immaterial. If you're writing a client application or applet you set the request type and URL and -- if it's a POST, open the POST stream to write the POST data. Beyond that, I can only recommend you read the URLConnection autodocs and/or a text on Java networking.
An IDE is no substitute for an Intelligent Developer.
I second the response that you should start by READING the JavaDoc for URLConnection and HttpURLConnection. If you do so you will find the following method in HttpURLConnection: public void setRequestMethod(String method) throws ProtocolException Set the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal, subject to protocol restrictions. The default method is GET. (BTW, when you get back a URLConnection from the constructor that uses a URL starting with "http://" what is really returned is an HttpURLConnection). Kyle
Thanks Anirban PS:I would like to correct myself . Kyle is right that HttpUrlConnection is indeed returned from UrlConnection .Otherwise , it would have thrown a run-time class-cast Exception. [This message has been edited by Anirban Chatterjee (edited November 16, 2001).]