I am learning Go and have come across this problem.
I just load the contents of a webpage using an HTTP client:
package main import ( "fmt" "io/ioutil" "log" "net/http" ) func main() { client := &http.Client{} req, err := http.NewRequest("GET", "https://mail.ru/", nil) req.Close = true response, err := client.Do(req) if err != nil { log.Fatal(err) } defer response.Body.Close() content, err := ioutil.ReadAll(response.Body) if err != nil { fmt.Println(err) } fmt.Println(string(content)[:100]) }
When reading the response body, an unexpected EOF error occurs. At the same time, the content variable has the full content of the page.
This error appears only when downloading content https://mail.ru/ . With other urls everything works fine - no errors.
I used curl to load the contents of this page - everything works as expected.
I'm a little confused - what's going on here?
Go v1.2, tried Ubuntu and MacOS X
Alex emelin
source share