Created
November 16, 2018 05:15
-
-
Save DQNEO/bd7de2f884da2a7b1a1cd013e184a9ba to your computer and use it in GitHub Desktop.
Go httpclient sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "io/ioutil" | |
| "log" | |
| "net/http" | |
| ) | |
| func main() { | |
| get() | |
| } | |
| func get() { | |
| client := &http.Client{} | |
| res, err := client.Get("https://httpbin.org/get?foo=1&bar=2") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| text, err := ioutil.ReadAll(res.Body) | |
| res.Body.Close() | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| fmt.Printf("%s", text) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment