View RSS Feed

Java Socket

HTTP GET and POST

Rate this Entry
by , 04-25-2012 at 10:32 PM (1440 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:
Java Code:
URL url = new URL("http://test.com");

URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
Once setDoOutput(true) is called open URLConnection's OutputStream, like this:
Java Code:
OutputStream output = urlConnection.getOutputStream();
Any data could be written by OutputStream in HTTP request body.

Remember that OutputStream shall be closed when writing data has been done to it.

Submit "HTTP GET and POST" to Facebook Submit "HTTP GET and POST" to Digg Submit "HTTP GET and POST" to del.icio.us Submit "HTTP GET and POST" to StumbleUpon Submit "HTTP GET and POST" to Google

Categories
Tutorial

Comments