View RSS Feed

Java Socket

Socket programming and networking examples in Java.

  1. HTTP GET and POST

    by , 04-25-2012 at 11:32 PM
    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();
    ...
    Categories
    Tutorial