HTTP Client
This program demonstrates making an HTTP GET request to the "https://gobyexample.com" website and printing the first five lines of the response body. Here's a breakdown of the code:
Output
Explanation:
The
http.Get
function is used to make an HTTP GET request to the specified URL ("https://gobyexample.com"). The response and any error are checked.The
defer
statement ensures that the response body is closed when the function exits.The response status is printed to the console.
A
bufio.Scanner
is created to read the response body line by line.A loop is used to read and print the first five lines of the response body.
Any errors that occurred during scanning are checked and handled.
You can run the program to see the response status and the first five lines of the HTML content from "https://gobyexample.com".
Last updated
Was this helpful?