package main //tcp 連接 http import ( "os" "fmt" "net" "io/ioutil" ) func main() { if len(os.Args)<=1 { fmt.Println("參數太少") os.Exit(1) } var service = os.Args[1] // 撥號 返回 網址ip var con,_ = net.ResolveTCPAddr("tcp4",service) fmt.Println(con) // 開始連接 var conn,_ =net.DialTCP("tcp",nil,con) var _,_ = conn.Write([]byte("HEAD / HTTP/1.0\r\n\r\n")) var res,_=ioutil.ReadAll(conn) fmt.Println(string(res)) }