I am trying to implement an API at the moment, in the first step a session is created, and after this sesson is queried with a get request. Sometimes I get a response code of 304 Not Modified – the results have not been modified since the last poll, and it seems to be all random to me. In this case I am unable to save the response into a Golang structure. It is very frustrating. Do you have any insights what could be the problem? Thanks!
client := &http.Client{Timeout: 10 * time.Second}
req, err := http.NewRequest("GET", url, nil)
q := req.URL.Query()
q.Add("apiKey", apiKey)
q.Add("sortorder", "asc")
req.URL.RawQuery = q.Encode()
if err != nil {
panic(err)
}
req.Header.Set("ACCEPT", "application/json")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode == 200{
if err != nil {
panic(err)
}
}else{
fmt.Println(resp.StatusCode)
}
data, err := ioutil.ReadAll(resp.Body)
return []byte(data)
Okay, problem has been solved by waiting for 1 second and polling again.