37 lines
No EOL
716 B
Markdown
37 lines
No EOL
716 B
Markdown
````go
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
func main() {
|
|
url := "https://www.zauberturm.de/Downloads/demo.txt"
|
|
// Make a GET request to the URL
|
|
response, err := http.Get(url)
|
|
if err != nil {
|
|
fmt.Println("Error making GET request:", err)
|
|
return
|
|
}
|
|
defer response.Body.Close()
|
|
// Check if the response status code is OK (200)
|
|
if response.StatusCode != http.StatusOK {
|
|
fmt.Println("Error: Unexpected status code", response.StatusCode)
|
|
return
|
|
}
|
|
|
|
// Read the content of the response body
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
if err != nil {
|
|
fmt.Println("Error reading response body:", err)
|
|
return
|
|
}
|
|
|
|
// Display the content of the downloaded file
|
|
fmt.Println(string(body))
|
|
}
|
|
``` |