I'm trying to send a GET web request using Go's http.NewRequest to a URL that contains special characters without any luck. Here's the URL structure:
https://example.com/page/page2?token=R9afij/GFGjm==&ref-uri=/&my-keywords=something
Here is how I'm trying to send it:
req, err := http.NewRequest("GET", "https://www.example.com/page/page2?token="+token+"ref-uri="+"/"+"&my-keywords="+keywords, nil)
if err != nil {
log.Printf("Critial ERRROR - Cannot setup new request with error: %s" + err.Error())
}
The error I receive is:
Critial ERRROR - Cannot setup new request with error: %!s(MISSING)parse "https://www.example.com/page/page2?token=RkIfiurkqlXvaK3q8JZDw==ref-uri=%!F(MISSING)&my-keywords=GMJYNE\r\n": net/url: invalid control character in URL
I've tried to add url.QueryEscape for the variables in the URL only but that doesn't seem to work as well and it breaks either the entire URL or each individual variable, ref-URI, or the keyword.
I've also tried with url.Values{} and placing each pair inside using the .Add(value, value) but that doesn't seem to work either, or I'm not using it correctly.
I've tried searching for quite some time but can't seem to find the right approach to this. Any assistance or guidance will be very much appreciated.
Aucun commentaire:
Enregistrer un commentaire