CN Lab Report 02
CN Lab Report 02
Student Details
Name ID
Implementation of the GET HTTP method using JAVA for the webpage
"YouTube.com" & "http:\\green.edu.bd".
2. OBJECTIVES/AIM
To get more knowledge about how to implement the HTTP GET method in
Codeblocks, some objectives here:
● To gather knowledge of different types of HTTP GET method.
● To learn how HTTP GET method works
● To implement the widely-used HTTP GET method.
import java.net.URL;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class HTTPGET {
public static void main(String[] args) throws IOException {
URL url = new URL("https://www.youtube.com/");
HttpURLConnection connect = (HttpURLConnection)url.openConnection();
connect.setRequestMethod("GET");
connect.setRequestProperty("User-Agent", "Chrome");
int response = connect.getResponseCode();
System.out.println("Response Code: " + response);
System.out.println("ResponseMessage:"+connect.getResponseMessage());
if (response == 200) {
InputStreamReader in = new InputStreamReader(connect.getInputStream());
BufferedReader read = new BufferedReader(in);
String store="";
StringBuffer str = new StringBuffer();
while ((store = read.readLine()) != null) {
str.append(store);
}
System.out.println("GET Response: " + str.toString());
}
}
}
The tests that I ran to determine my program accurately with solving the stated
problem. Here the output for the following above code:
Output :
Figure 01: HTTP GET method output for the webpage "YouTube.com"
Figure 02: HTTP GET method output for the webpage "green.edu.bd"