HttpURLConnection SetRequestMethod() Example

Set the method for the URL request,


HttpURLConnectionclass SetRequestMethod() method example. This example shows you how to use SetRequestMethod() method.This method Set the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal, subject to protocol restrictions.

Here is the code:-
/* 
 * @Program that Set the method for the URL request
 * SetRequestMethod.java 
 * Author:-RoseIndia Team
 * Date:-25-Jun-2008
 */

import java.net.*;
import javax.annotation.PostConstruct;

public class SetRequestMethod {

    public static void main(String[] argsthrows Exception {
        URL url = new URL("http://192.168.10.211:8080");
        HttpURLConnection connection = (HttpURLConnectionurl.openConnection();
        //Get the request method.
        String s = connection.getRequestMethod();
        System.out.println("Get the request method: " + s);
        //Set the method for the URL request
        connection.setRequestMethod("POST");
         String s1 = connection.getRequestMethod();
        System.out.println("Get the request method: " + s1);
    }
}

Output of the program:-
 Get the request method: GET
Get the request method: POST

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US