I have a standard piece of go http request that I am trying to get right in the code below.
func IssueSearchQuery(conf Config) (string, error) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
var client = &http.Client{
Timeout: time.Second * 60,
Transport: tr,
}
URL := conf.URL + "/api/search"
v := url.Values{}
v.Set("query_expression", "select * from test")
req, err := http.NewRequest("POST", URL,
bytes.NewBufferString(v.Encode()))
req.SetBasicAuth(conf.User, conf.Password)
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
bodyText, err := ioutil.ReadAll(resp.Body)
s := string(bodyText)
return s, err
}
In the above code, I am connecting to the server, basic authentication works, but the server responds complaining saying the required query_expression
query parameter is missing. If I do curl -u user:pass -d "query_expression=select * from test" --insecure -XPOST 'https://ip:port/api/search'
the server responds with the required result.
The code also works if I don't use url.Values{} and instead manually encode my query into the url like URL := conf.URL + "/api/ariel/searches?query_expression=select%20*20from%20test"
I am not able to figure out what I am doing wrong with my query parameters. Can someone help? Thanks!