I’ve the below url that is getting a JSON as responce:
https://script.google.com/macros/s/AKfycbzw0TKWycxeB5sx1wIefAiEHeYQt2mVuM-NAZTccxedhyntdv8FvcUteOZ2k03wRHGE/exec?barcode=6287029390129
Trying to get the same output through GO, so I wrote the below Go Playground - The Go Programming Language
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://script.google.com/macros/s/AKfycbzw0TKWycxeB5sx1wIefAiEHeYQt2mVuM-NAZTccxedhyntdv8FvcUteOZ2k03wRHGE/exec?", nil)
q := req.URL.Query()
q.Add("barcode", "6287029390129")
//q.Add("another_thing", "foo & bar")
req.URL.RawQuery = q.Encode()
fmt.Println(req.URL.String())
// url := "https://script.google.com/macros/s/AKfycbzw0TKWycxeB5sx1wIefAiEHeYQt2mVuM-NAZTccxedhyntdv8FvcUteOZ2k03wRHGE/exec?barcode=6287029390129"
resp, err := http.Get(req.URL.RawQuery) //
_ = req.URL.RawQuery
if err != nil {
log.Fatalln(err)
}
//We Read the response body on the line below.
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
//Convert the body to type string
sb := string(body)
log.Printf(sb)
}
But I got the below error:
2009/11/10 23:00:00 Get "barcode=6287029390129": unsupported protocol scheme ""
UPDATE
Based on some comments recieved, I changed resp, err := http.Get(req.URL.RawQuery)
to be: resp, err := http.Get(req.URL.String())
, also I used it as: resp, err := http.DefaultClient.Do(req)
Go Playground - The Go Programming Language
But I got the below error in both cases:
2009/11/10 23:00:00 Get "https://script.google.com/macros/s/AKfycbzw0TKWycxeB5sx1wIefAiEHeYQt2mVuM-NAZTccxedhyntdv8FvcUteOZ2k03wRHGE/exec?barcode=6287029390129": dial tcp: lookup script.google.com on 169.254.169.254:53: dial udp 169.254.169.254:53: connect: no route to host