How to Make a Http GET request and read response

Steps to make a HTTP GET request

  1. Make URL object.
  2. Make HttpURLConnection object from URL object and type cast it to HttpURLConnection
  3. Set Request method to GET.
  4. Add Headers using method setRequestProperty() if required.
  5. Use BufferedReader to read the input stream of the connection.
  6. Read the response from buffered reader object.
The code to implement the above steps is shown below.