Sunday, November 19, 2017

LAB 16 - HTTP RESPONSE


import java.io.*;

import java.net.*;



class HTTPRES

{

public static void main (String args[]) throws Exception

    {

        // to retrieve the contents of this webpage

        URL url = new URL("http://google.com");

        HttpURLConnection connection = (HttpURLConnection)url.openConnection();



        // a connection is made

        connection.setRequestMethod("GET");

        connection.connect();



        // to get response code

        int code = connection.getResponseCode();



        //print the response code

        System.out.println("Response code of the object is "+code);



        //response code 200 = ok

        if (code==200)

        {

System.out.println("OK");

        }



    }

}



OUTPUT



Response code of the object is 200



OK



BUILD SUCCESSFUL (total time: 1 second)




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.