8
7

More than 5 years have passed since last update.

http.client.Doでretryをするとき

Last updated at Posted at 2015-07-16

これでいけるかな?と思ってたけど

client := &http.Client{}
req, _ := http.NewRequest("POST", "http://localhost", bytes.NewBuffer([]byte(`test`))) 

resp, err := client.Do(req)
if err != nil {
  resp, err = client.Do(req)
}

けど

client := &http.Client{}
req, _ := http.NewRequest("POST", "http://localhost", bytes.NewBuffer([]byte(`test`))) 

resp, err := client.Do(req)
if err != nil {
  req, _ := http.NewRequest("POST", "http://localhost", bytes.NewBuffer([]byte(`test`))) 
  req.Header.Set("Content-Type", "application/json") 
  resp, err = client.Do(req)
}

requestを作りなおさないと行けないみたい
もし再利用する方法があれば教えてください

8
7
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7