HTTP Client

Download go eBook

Syntax

  • resp, err := http.Get(url) // Makes a HTTP GET request with the default HTTP client. A non-nil error is returned if the request fails.
  • resp, err := http.Post(url, bodyType, body) // Makes a HTTP POST request with the default HTTP client. A non-nil error is returned if the request fails.
  • resp, err := http.PostForm(url, values) // Makes a HTTP form POST request with the default HTTP client. A non-nil error is returned if the request fails.

Parameters

ParameterDetails
respA response of type *http.Response to an HTTP request
errAn error. If not nil, it represents an error that occured when the function was called.
urlA URL of type string to make a HTTP request to.
bodyTypeThe MIME type of type string of the body payload of a POST request.
bodyAn io.Reader (implements Read()) which will be read from until an error is reached to be submitted as the body payload of a POST request.
valuesA key-value map of type url.Values. The underlying type is a map[string][]string.

Remarks

It is important to defer resp.Body.Close() after every HTTP request that does not return a non-nil error, else resources will be leaked.

Related Examples

Stats

1154 Contributors: 5
Sunday, July 30, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook