gobyexample/059-http-client-basic/http-client-basic.go
Mark McGranaghan 70dd607774 updates
2012-09-23 12:36:08 -07:00

19 lines
423 B
Go

// ## HTTP Client Basic Auth
package main
import "net/http"
import "io/ioutil"
import "fmt"
func main() {
req, _ := http.NewRequest("GET", "http://127.0.0.1:5000/", nil)
req.SetBasicAuth("u", "supersecret")
res, resErr := http.DefaultClient.Do(req)
if resErr != nil { panic(resErr) }
defer res.Body.Close()
body, bodyErr := ioutil.ReadAll(res.Body)
if bodyErr != nil { panic(bodyErr) }
fmt.Print(string(body))
}