Golang net/http.ReadResponse() function example

package net/http

Golang net/http.ReadResponse() function usage example

 var network string
 var address string
 conn, err := net.Dial(network, address)
 if err != nil {
 panic(err)
 }
 resp, err := http.ReadResponse(bufio.NewReader(conn), &http.Request{Method: "CONNECT"})

 if err == nil && resp.Status == connected {
 // do something
 }
 if err == nil {
 err = errors.New("unexpected HTTP response: " + resp.Status)
 }
 conn.Close()

References :

https://golang.org/src/net/rpc/client.go

http://golang.org/pkg/net/http/#ReadResponse

Advertisement