```
package main
import (
"fmt"
"net"
"net/http"
"time"
)
var (
url = []string{
"http://www.baidu.com",
"http://google.com",
"http://taobao.com",}
)
func main() {
for _ , v := range url{
//设置2秒超时
c := http.Client{
Transport:&http.Transport{
Dial:func(network, addr string) (net.Conn, error){
timeout := time.Second * 2
return net.DialTimeout(network,addr,timeout)
},
},
}
resp, err := c.Head(v)
if err != nil {
fmt.Println("http.Head err=",err)
continue
}
fmt.Println("http.Head success status=",resp.Status)
}
}
```
有疑问加站长微信联系(非本文作者))