Go实例: HTTP Clients

Ivie ·
更新时间:2024-11-13
· 493 次阅读

package main import ( "bufio" "fmt" "net/http" ) func main() { resp, err := http.Get("http://gobyexample.com") if err != nil { panic(err) } defer resp.Body.Close() fmt.Println("Response status:", resp.Status) scanner := bufio.NewScanner(resp.Body) for i := 0; scanner.Scan() && i < 5; i++ { fmt.Println(scanner.Text()) } if err := scanner.Err(); err != nil { panic(err) } }$ go run http-clients.go Response status: 200 OKGo by Example



GO实例 HTTP GO

需要 登录 后方可回复, 如果你还没有账号请 注册新账号