Skip to content

Instantly share code, notes, and snippets.

@JiaxiangZheng
Forked from ijt/http_get.go
Created February 24, 2014 05:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JiaxiangZheng/9182624 to your computer and use it in GitHub Desktop.
Save JiaxiangZheng/9182624 to your computer and use it in GitHub Desktop.
demonstrate how to fectch web page given the URL
package main
import (
"fmt"
"net/http"
"io/ioutil"
"os"
)
func main() {
response, err := http.Get("http://golang.org/")
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Printf("%s\n", string(contents))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment