url := "https://google.com/"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatal(err)
fmt.Printf(err.Error())
return
}
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
fmt.Printf(err.Error())
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
fmt.Printf(err.Error())
return
}
fmt.Printf("testing")
fmt.Println(BytesToString(body))
The above code block worked ok for me on IOS
On Friday, April 20, 2018 at 11:38:56 AM UTC-5, yanqiang yang wrote:
>
> http.Get doesn't work with default transport, but works fine if I set a
> custom as following(uncomment the two lines)
>
> package main
>
> import (
> "net/http"
> "io/ioutil"
> "fmt"
> "log"
> )
> func main() {
> //tr := &http.Transport{}
> //http.DefaultClient.Transport =tr
> res, err:= http.Get("https://www.github.com/")
> if err != nil {
> log.Fatal(err)
> return
> }
>
> defer res.Body.Close()
>
> body,err:=ioutil.ReadAll(res.Body)
> if err != nil {
> log.Fatal(err)
> return
> }
>
> fmt.Println(string(body))
> }
>
> There is an error with less meaning:
> Get https://www.github.com/: unexpected EOF
>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.