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

Com Report 1

This lab report details the implementation of HTTP GET and POST methods in a Java application, highlighting their roles in web communication. The GET method is used to request data from servers, while the POST method is for sending data to servers. The report includes algorithms, code implementations, and testing results demonstrating the functionality of both methods.
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)
2 views5 pages

Com Report 1

This lab report details the implementation of HTTP GET and POST methods in a Java application, highlighting their roles in web communication. The GET method is used to request data from servers, while the POST method is for sending data to servers. The report includes algorithms, code implementations, and testing results demonstrating the functionality of both methods.
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

lOMoARcPSD|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_D5

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

Student Details
Name ID

1. Md Rezanur Bin Shamim 221902305

Lab Date : 23.02.2025


Submission Date : 02.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:..............................
lOMoARcPSD|382 166 66

1. TITLE OF THE LAB EXPERIMENT

HTTP (Hypertext Transfer Protocol) is a fundamental protocol used for communication on the World Wide
Web. HTTP encompasses several methods, including GET and POST, which are employed to request and
transmit data between clients (typically web browsers) and web servers. This lab focuses on implementing
these methods in a Java application to illustrate their functionality.

2. OBJECTIVES/AIM

HTTP GET and POST are two ways your browser (or any app) talks to a website's server.

• GET is like asking for information. When you open a webpage, search on Google, or view an
image, your browser sends a GET request to the server, and the server sends back the data.
• POST is like sending information. When you fill out a form (like logging in or signing up),
uploading a file, or submitting a comment, your browser sends a POST request to the server with
your data so it can be processed or stored.

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
lOMoARcPSD|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);
}
}
lOMoARcPSD|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)
lOMoARcPSD|382 166 66

Fig-1.2(GET Method)

6. ANALYSIS AND DISCUSSION

Testing the GET Method

1. We created an object of HTTPMethodsExample.


2. We used the sendGetRequest method to send a GET request to a website.
3. We got a response and displayed it.

Testing the POST Method

1. We created an object of HTTPMethodsExample.


2. We used the sendPostRequest method to send data to a website.
3. We got a response and displayed it.

Analysis and Discussion

The program worked as expected. We sent a GET request to webcode.me and successfully received a
response.
We tested the GET method in different environments, which helped us understand how responses can
vary. However, POST is usually preferred for secure data submission.

7. SUMMARY:

The lab report on the "Implementation of HTTP GET and POST Methods in Java" describes a practical
exploration of using these HTTP methods within a Java application. HTTP GET and POST methods are
fundamental for web communication, enabling clients to request data from servers (GET) or send data to
servers (POST).

You might also like