Show request method for a http connection in Java

Description

The following code shows how to show request method for a http connection.

Example


//  www.ja va  2  s .  co m

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;

public class Main{
  public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.google.com");
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();

    System.out.println("Request method is " + httpCon.getRequestMethod());

 }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode