5

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.

1 Answer 1

10

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()) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.