Golang - Enter/Input a URL Using Get Function in HTTP, and checking the response status code Code Example

The code for Enter/Input a URL Using Get Function in HTTP, and checking the response status code

package main
 
import (
    "fmt"
    "net/http"
    "log"
)
 
func main() {
    var url string
    fmt.Print("Enter the website's URL: ")
    fmt.Scan(&url)
    resp,err := http.Get(url)
    if err != nil {
        log.Fatal(err)
    }
    status_code := resp.StatusCode
    fmt.Println(status_code,":",url)
}

/*
Output:
Enter the website's URL: https://www.includehelp.com
2023/02/28 15:44:48 Get https://www.includehelp.com: 
dial tcp: lookup www.includehelp.com on 169.254.169.254:53: 
dial udp 169.254.169.254:53: connect: network is unreachable
*/
Code by IncludeHelp, on February 28, 2023 15:45

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.