0% found this document useful (0 votes)
18 views4 pages

CN Lab Report 02

Uploaded by

Sidratul Muntaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

CN Lab Report 02

Uploaded by

Sidratul Muntaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Fall, Year:2024), B.Sc. in CSE (Day)

Lab Report NO #02


Course Title: Computer Networking Lab
Course Code: CSE 312 Section: 221(D22)

Lab Experiment Name: Implementation of the GET HTTP method


using JAVA for the webpage "YouTube.com" &
"http:\\green.edu.bd".

Student Details
Name ID

1. Raysha Rahman 221002533

Lab Date : 19-09-2024


Submission Date : 25-09-2024
Course Teacher’s Name : Sharifur Rahman

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
1. TITLE OF THE LAB REPORT EXPERIMENT:

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.

3. PROCEDURE / ANALYSIS / DESIGN


To implement the HTTP GET method in Codeblocks,some steps are needed:
● Step 1: Start.
● Step 2: Instantiate a URL object with the target URL for the GET request.
● Step 3: Use the openConnection() method on the URL object to establish
a connection and cast it to `HttpURLConnection`.
● Step 4: Call setRequestMethod("GET") to configure the connection to use
the GET method.
● Step 5: Use setRequestProperty() to set headers such as User-Agent to
specify the request type.
● Step 6: Skip setting `setDoOutput(true)`, as GET requests do not send
data to the server and do not require output stream configuration.
● Step 7: Do not use OutputStream as GET requests do not send a request
body. Skip this step.
● Step 8: Call getResponseCode() to send the request and retrieve the
HTTP response code.
● Step 9: If the response code indicates success, use an
‘InputStreamReader’ and ‘BufferReader’ to read and display the
response.
● Step 10: End.
4. IMPLEMENTATION
For execute the problem some steps are needed.The necessary source
code attached here:

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());
}
}
}

5. TEST RESULT / OUTPUT

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"

6. ANALYSIS AND DISCUSSION

The result/output that provides for executing the networking problems


implementation in Cisco .Yes,here the maximum path that was comfortably helped
to reach the perception. Actually this was my first practice problem about the HTTP
GET method at Networking Lab . So I made some mistakes for the first time. First
understanding then the procedure and that is really difficult to say to reach the
expectation at first too much.Some mistake that was the most troubled part of my
program execution.The best part of this assignment that was liked by me and it was
the HTTP GET request.The lab exercise will help me to practise HTTP GET
requests and also help them to be confident towards the fulfilment of the objectives.

You might also like