0% found this document useful (0 votes)
6 views5 pages

Com Report 01

The lab report focuses on the implementation of HTTP GET and POST methods in a Java program, demonstrating how these protocols facilitate web communication. The experiment includes algorithms for both methods and provides sample Java code for executing GET and POST requests. The report concludes with an analysis of the results, highlighting the successful operation of the methods and the differences in their use cases.
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)
6 views5 pages

Com Report 01

The lab report focuses on the implementation of HTTP GET and POST methods in a Java program, demonstrating how these protocols facilitate web communication. The experiment includes algorithms for both methods and provides sample Java code for executing GET and POST requests. The report concludes with an analysis of the results, highlighting the successful operation of the methods and the differences in their use cases.
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/ 5

lOMoAR cPSD| 382 166 66

Green University of Bangladesh


Department of Computer Science and Engineering (CSE)
Faculty of Sciences and Engineering
Semester: (Spring, Year: 2025), B.Sc. in CSE (Day)

LAB REPORT NO: 01


Course Title: Computer Networking Lab
Course Code: CSE-312 Section: 223_D3

Lab Experiment Name: Implementation of HTTP GET and POST Methods.


Student Details
Name ID

1. Durjoy Kumar Pranto 221902312

Lab Date : 24.02.2025


Submission Date : 24.03.2025
Course Teacher’s Name : Rusmita Halim Chaity

[For Teachers use only: Don’t Write Anything inside this box]
Lab Report Status
Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
lOMoAR cPSD| 382 166 66

1. TITLE OF THE LAB EXPERIMENT

One essential protocol for online communication is HTTP (Hypertext Transfer Protocol). HTTP includes a number
of techniques, such as GET and POST, that are used to request and send data between web servers and clients,
usually web browsers. In order to demonstrate these techniques' functionality, this lab focuses on putting them
into practice in a Java program.

2. OBJECTIVES/AIM

Your browser (or any app) can communicate with a website's server in two ways: HTTP GET and POST.

• GET is similar to requesting information. Your browser makes a GET request to the server whenever you open
a webpage, conduct a Google search, or view an image, and the server responds with the information.

• POST is similar to information transmission. When you leave a comment, upload a file, or complete a form
(such as checking in or signing up), your browser makes a POST request to the server with your information so
that it can be processed or saved.

3. PROCEDURE / ANALYSIS / DESIGN


In this experiment we perform two operations for HTTP GET and POST method.Here given the
algorithm to understand how this method works.
1. Algorithm(GET Method)
Step 1: Create a url (https://jsonplaceholder.typicode.com/posts/)
Step 2: HTTP connection (openConnection())
Step 3: Configure connection setRequestMethod(“POST”) Step
4: Prepare Data “create string conating”
Step 5: Send Data “outputStream and write string content”
Step 6: verifying “responseCode = = HTTP_CREATED
Step 7: Read response: “bufferReader”
Step 8: execute posted content
Step 9: END
2. Algorithm(POST Method)
Step 1: Create URL “HTTPConnection, openConnection();
Step 2: Configure connection “setRequestMethod(“GET”);
Step 3: Check response “if responseCode = = HTTP_OK
Read content; print the string
Else; print error message Step
4: EXIT
lOMoAR cPSD| 382 166 66

4. IMPLEMENTATION

● HTTP(POST) Method
package cse312;

import java.io.BufferedReader; import java.io.IOException; import


java.io.InputStreamReader; import java.io.OutputStream; import
java.net.*; public class HTTP_GET { public static void main(String[]
args) throws
MalformedURLException, IOException {
URL url = new URL("https://jsonplaceholder.typicode.com/posts/");
HttpURLConnection conn = (HttpURLConnection)
url.openConnection(); conn.setRequestMethod("POST");
conn.setDoOutput(true);
OutputStream out = conn.getOutputStream(); String
str = "Hi!!! Connection Successfully ";
out.write(str.getBytes());
int responseCode = conn.getResponseCode();
if(responseCode == HttpURLConnection.HTTP_CREATED){
System.out.println( responseCode);
System.out.println(conn.getResponseMessage());
}else{
System.out.println("Go to Home");
}
InputStreamReader in = new InputStreamReader(conn.getInputStream());
BufferedReader buffer = new BufferedReader(in);
String eachline = null;
StringBuffer strBuffer = new StringBuffer();
while((eachline =
buffer.readLine())!=null){
strBuffer.append(eachline); }
System.out.println(strBuffer);
}
}
lOMoAR cPSD| 382 166 66

● HTTP(POST) Method

package cse312; import java.io.BufferedReader; import


java.io.IOException; import java.io.InputStreamReader; import
java.io.OutputStream; import java.net.*; public class HTTP_POST {
public static void main(String[] args) throws MalformedURLException,
IOException {
URL url = new URL("https://jsonplaceholder.typicode.com/posts/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("POST"); conn.setDoOutput(true);
OutputStream out = conn.getOutputStream(); String
str = "Hi!!! Connection Successfully ";
out.write(str.getBytes());
int responseCode = conn.getResponseCode();
if(responseCode == HttpURLConnection.HTTP_CREATED){
System.out.println( responseCode);
System.out.println(conn.getResponseMessage());
}else{
System.out.println("Go to Home");
}
InputStreamReader in = new InputStreamReader(conn.getInputStream());
BufferedReader buffer = new BufferedReader(in);
String eachline = null;
StringBuffer strBuffer = new StringBuffer();
while((eachline =
buffer.readLine())!=null){
strBuffer.append(eachline); }
System.out.println(strBuffer);
}
}

5. TEST RESULT / OUTPUT

Fig-1.1(POST Method)
lOMoAR cPSD| 382 166 66

Fig-1.2(GET Method)

6. ANALYSIS AND DISCUSSION

Examining the GET Method

1. We produced an HTTPMethodsExample object.

2. We sent a GET request to a website using the sendGetRequest function.

3. After receiving an answer, we showed it. Examining the POST Method

1. We produced an HTTPMethodsExample object.

2. To submit data to a website, we employed the sendPostRequest function.

3. After receiving an answer, we showed it.

Evaluation and Conversation

The program operated as planned. We successfully obtained a response from webcode.me after sending them a
GET request.

In order to better understand how replies can differ, we evaluated the GET method in various situations.
However, for safe data submission, POST is typically recommended.

7. SUMMARY:

The "Implementation of HTTP GET and POST Methods in Java" lab report discusses a hands-on investigation
into utilizing these HTTP methods in a Java application. Web communication relies on the HTTP GET and
POST protocols, which allow clients to transmit data to servers (POST) or obtain data from servers (GET).

You might also like