HttpURLConnection GetResponseCode() Example

Gets the status code from an HTTP response message.


HttpURLConnectionclass GetResponseCode() method example. This example shows you how to use GetResponseCode() method.This method Gets the status code from an HTTP response message.

Here is the code:-
/* 
 * @Program that Gets the status code from an HTTP response message.
 * GetResponseCode.java 
 * Author:-RoseIndia Team
 * Date:-25-Jun-2008
 */

import java.net.*;

public class GetResponseCode {

    public static void main(String[] argsthrows Exception {
        URL url = new URL("http://192.168.10.211:8080");
        HttpURLConnection connection = (HttpURLConnectionurl.openConnection();
        // // Gets the status code from an HTTP response message.
        int i = connection.getResponseCode();
        System.out.println(" Code from an HTTP response message is: " + i);
    }
}

Output of the program:-
 Code from an HTTP response message is: 200

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

HOME | COPYRIGHT | CONTACT US