1

How can I add a query parameter which is a timestamp in RFC3339 without URL encoding? This question is an extension of Go doing a GET request and building the Querystring

package main import ( "fmt" "net/http" "time" ) func main() { req, _ := http.NewRequest("GET", "http://api.themoviedb.org/3/tv/popular", nil) t := time.Now() q := req.URL.Query() q.Add("api_key", "key_from_environment_or_flag") q.Add("another_thing", "foo & bar") q.Add("timestamp", t.Format(time.RFC3339)) req.URL.RawQuery = q.Encode() fmt.Println(t.Format(time.RFC3339)) fmt.Println(req.URL.String()) // Output: // 2009-11-10T23:00:00Z // http://api.themoviedb.org/3/tv/popular?another_thing=foo+%26+bar&api_key=key_from_environment_or_flag&timestamp=2009-11-10T23%3A00%3A00Z } 

I want

http://api.themoviedb.org/3/tv/popular?another_thing=foo+%26+bar&api_key=key_from_environment_or_flag&timestamp=2009-11-10T23:00:00Z

https://play.golang.org/p/2rg-qXZNx2a

Thank you

4
  • 3
    The question is why do you want the URL without encoding? Any URL parser will interpret your URL as it having timestamp=2009-11-10T23:00:00Z. Commented May 19, 2020 at 17:02
  • @icza the api I am accessing apparently does not interpret the URL correctly Commented May 19, 2020 at 17:05
  • 4
    req.URL.RawQuery = q.Encode() + t.Format("&timestamp="+time.RFC3339) Commented May 19, 2020 at 17:09
  • I have the same problem, is your API an OData API by chance ? Because yes, the "dollar" sign is encoded to "%24" and the API is unable to understand it... In that case it is RSA Archer Commented Dec 15, 2020 at 15:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.