cizixs cizixs - 1 year ago 143
HTTP Question

What are possible golang http response errors?

As in many golang

articles, a request returns two values: response and error:

resp, err := http.Get("")
if err != nil {
// handle error
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)

For http-related errors, it will be returned in
with status code like 502, 400 etc. What are the possible errors returned? I need to know them before I can handle them.

Answer Source
  1. URL parse error
  2. too much redirect times
  3. tcp connect\write\read timeout
  4. 302 status, but null Location header

and so on

You can read the source code in http package. Then you can find all the errors returned by this function http.Get.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download