Com Report 01
Com Report 01
[For Teachers use only: Don’t Write Anything inside this box]
Lab Report Status
Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
lOMoAR cPSD| 382 166 66
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.
4. IMPLEMENTATION
● HTTP(POST) Method
package cse312;
● HTTP(POST) Method
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);
}
}
Fig-1.1(POST Method)
lOMoAR cPSD| 382 166 66
Fig-1.2(GET Method)
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).