0% found this document useful (0 votes)
58 views3 pages

Green University of Bangladesh Department of Computer Science and Engineering (CSE)

This lab report summarizes a computer networking lab experiment where the student implemented the HTTP POST method in Java. The student's objective was to learn about and solve HTTP POST using Java. They created Java code to send a POST request with JSON data to a URL, write the response, and check that the response code was 201 (Created). The student reports that they implemented the code successfully and completed the lab experiment objectives.

Uploaded by

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

Green University of Bangladesh Department of Computer Science and Engineering (CSE)

This lab report summarizes a computer networking lab experiment where the student implemented the HTTP POST method in Java. The student's objective was to learn about and solve HTTP POST using Java. They created Java code to send a POST request with JSON data to a URL, write the response, and check that the response code was 201 (Created). The student reports that they implemented the code successfully and completed the lab experiment objectives.

Uploaded by

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

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Summer 2021), B.Sc. in CSE (Evening)

LAB REPORT NO # 03
Course Title: Computer Networking Lab
Course Code: CSE 312 Section: 192EA

Lab Experiment Name: Implementation of HTTP POST Method in JAVA

Student Details

Name ID
1. Nahid Hasan Ridoy 192015031

Lab Date : Nov 5, 2021


Submission Date : Dec 28, 2021
Course Teacher’s Name : Tanpia Tasnim

[For Teachers use only: Don’t Write Anything inside this box]

Lab Report Status Marks: …………………………………


Comments:.............................................. Signature:.....................
Date:..............................
1. Objective(s)
• To learn about and solve HTTP POST Method using JAVA in this
lab Experiment.

2. IMPLEMENTATION / CONFIGURATION

package lab02;
import java.net.URL;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;

public class lab02 {

public static void main(String[] args) throws IOException {


final String POST = "{\n" + " \"Name\": \"D. M. Shanto Islam\",\r\n"
+ " \"S_Id\": \"191015138\",\r\n"
+ " \"id\": \"191E\",\r\n"
+ " \"Result\": \"Successful\"" + "\n}";
System.out.println(POST);
URL url = new URL("https://jsonplaceholder.typicode.com/posts");
HttpURLConnection postConnection = (HttpURLConnection) url.openConnection();
postConnection.setRequestMethod("POST");
postConnection.setRequestProperty("S_Id", "a1bcdefgh");
postConnection.setRequestProperty("Content-Type", "application/json");
postConnection.setDoOutput(true);
OutputStream write = postConnection.getOutputStream();
write.write(POST.getBytes());
write.flush();
write.close();
int response = postConnection.getResponseCode();
System.out.println("POST Response : " + response);
System.out.println("POST Response Message : " + postConnection.getResponseMessage());
if (response == HttpURLConnection.HTTP_CREATED) {
BufferedReader in = new BufferedReader(new InputStreamReader(
postConnection.getInputStream()));
String inputLine;
StringBuffer response1 = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response1.append(inputLine);
}
in.close();
System.out.println(response1.toString());
} else {
System.out.println("POST NOT WORKED");
}
}
}
Figure:

Result:
I implement this code successfully.

SUMMARY
I complete this lab experiment successfully.

You might also like