Computer Networking Lab
This is a simple Java application that demonstrates how to make an HTTP GET request to a REST API endpoint using Java's HttpURLConnection. The application fetches data from https://jsonplaceholder.typicode.com/posts, prints the response code and message, and displays the retrieved JSON data.
- Establishes an HTTP connection to a given URL
- Sends a GET request with a custom User-Agent header
- Reads and prints the response status code and message
- Fetches and displays the full response data from the API
To run this project, ensure you have the following installed:
- Java Development Kit (JDK) 8 or later
- Clone or download the project files.
- Open a terminal or command prompt in the project directory.
- Compile the Java program:
javac Networkingclass1.java
- Run the compiled class:
java com.mycompany.networkingclass1.Networkingclass1
When executed, the program should display:
- HTTP response code (e.g.,
200for success) - HTTP response message (e.g.,
OK) - The retrieved JSON response data from the API
- The API used (
https://jsonplaceholder.typicode.com/posts) is a free fake online REST API for testing and prototyping. - The response is printed as a single string; formatting may be necessary for better readability.
This project is open-source and free to use.