package main import ( "fmt" "io/ioutil" //[1] "net/http" //[2] "os" //[3] //"path/filepath" // [4] ) func main() { // if len(os.Args) != 2 { // fmt.Printf("useage:%s http://url", filepath.Base(os.Args[0])) // os.Exit(1) // } //var url string for i := 15190; i > 10153; i -= 1 { url := fmt.Sprintf("http://1222.42.772.2182:8088/index.php?p=20015&action=30&itemid=%d", i) resp, err := http.Get(url) //resp, err := http.Get(os.Args[1]) if err != nil { fmt.Println(err) //go语言会内含详细的错误描述,可以尝试不同的参数来测试 os.Exit(2) } defer resp.Body.Close() //The client must close the response body when finished with it: body, err2 := ioutil.ReadAll(resp.Body) //此处使用了包【1】 if err2 != nil { fmt.Println(err2) os.Exit(3) } fmt.Printf("%d ,%srn", i, body) } }