HTTP GET and POST
by, 04-25-2012 at 11:32 PM (1061 Views)
By default, HTTP GET requests are sent to webserver by URLConnection. Instead if HTTP POST request are required to be sent, URLConnection.setDoOutout(true) method shall be called, like:
Once setDoOutput(true) is called open URLConnection's OutputStream, like this:Java Code:URL url = new URL("http://test.com"); URLConnection urlConnection = url.openConnection(); urlConnection.setDoOutput(true);
Any data could be written by OutputStream in HTTP request body.Java Code:OutputStream output = urlConnection.getOutputStream();
Remember that OutputStream shall be closed when writing data has been done to it.