I want to send a text string in get request using net/http package in golang. But I'm unable to find out how to do that. Like I want to hit the following url:
"http://api.example.com/tutor?message=how can I do this"
Please let me know how can I do this.
Use this:
resp, err := http.Get("http://api.example.com/tutor?message=" + url.QueryEscape("how can I do this"))
Where url
the net/url package.
If you have multiple query parameters, you can use
p := url.Values{"message": {"hown ca I do this"}, "other": "whatever"}
resp, err := http.Get(`http://api.example.com/tutor?` + p.Encode())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With