Original post

I am getting getting error 406 with http post , and I am pretty sure request body is fine. I did it in Python , don't use on regulars basis. See code snippet below. The prettyJSON shows that body is correct (can send it thru postman without any issue to the same URL). What can be wrong ?

rb, err := json.Marshal(realServerItems[0])
if err != nil {
return nil, err
}
prettyJSON, _ := json.MarshalIndent(realServerItems[0], "", " ")
fmt.Printf("%sn",string(prettyJSON))
req, err := http.NewRequest("POST", fmt.Sprintf("%s/SlbNewCfgEnhRealServerTable/%s", c.HostURL, RealServerID), strings.NewReader(string(rb)))
if err != nil {
return nil, err
}
body, err := c.doRequest(req)
if err != nil {
return nil, err
}

and my do.Request below

func (c *Client) doRequest(req *http.Request) ([]byte, error) {
req.Header.Set("Authorization", c.Token)
res, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("status: %d, body: %s", res.StatusCode, body)
}
return body, err
}

submitted by /u/niuk007
[link] [comments]