I am running into a problem that for certain urls, code in Golang is not retrieving the expected content. I am not posting the actual url, but it has this form and is a link to a google drive file download https://docs.google.com/uc?id=somelongid&export=download
. If I use wget to get the file it works fine. I also have ruby code which uses open()
and it works as well. For some reason though Golang returns an empty buffer and no error. If I use this code to fetch some "ordinary" url like a static website it works as expected and returns non-empty response.Body. Below is code I extracted out of my project to simplify and narrow where the problem could be. Below is output.
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
resp, err := http.Get("myurlishere")
if err != nil {
fmt.Println("Something went wrong")
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Printf("Body: %v\n", body)
fmt.Printf("Error: %v\n", err)
}
Output
$go run main.go
Body: []
Error: <nil>