Created
August 21, 2014 15:17
-
-
Save andreagrandi/8dd30a82a89d7561f376 to your computer and use it in GitHub Desktop.
http.get() example to get a remote url and display its content
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 ( | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
) | |
var url = flag.String("u", "", "URL to read") | |
func main() { | |
flag.Parse() | |
resp, err := http.Get(*url) | |
if err != nil { | |
panic(err) | |
} | |
defer resp.Body.Close() | |
content, err := ioutil.ReadAll(resp.Body) | |
fmt.Println(string(content)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: go run get_client.go -u http://www.google.it