Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: get does not work #24970

Closed
yyq2013 opened this issue Apr 20, 2018 · 14 comments
Closed

net/http: get does not work #24970

yyq2013 opened this issue Apr 20, 2018 · 14 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@yyq2013
Copy link

yyq2013 commented Apr 20, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

C:\WINDOWS\system32>go version
go version go1.10.1 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

win10 64bit
C:\WINDOWS\system32>go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build873199622=/tmp/go-build -gno-record-gcc-switches

What did you do?

http.Get(url) doesn't work with default transport, if I set a custom it works fine like following:

	tr := &http.Transport{}
	http.DefaultClient.Transport =tr
        http.Get(url)...

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

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))
}

What did you expect to see?

Print the html content

What did you see instead?

There is an error with less meaning.
Get https://www.github.com/: unexpected EOF

@adamdecaf
Copy link
Contributor

I get a more descriptive error from this code. https://play.golang.org/p/_f2geOmnMzl

	res, err := http.Get("github.com")
	if err != nil {
		panic(err)
	}
	fmt.Println(res)
panic: Get github.com: unsupported protocol scheme ""

goroutine 1 [running]:
main.main()
	/tmp/sandbox333729466/main.go:11 +0xe0

Also, the Go project does not use its bug tracker for general discussion or asking questions. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process.

Please see the Questions wiki page; it has a list of good places for asking questions. Thanks!

@agnivade agnivade changed the title http get not work net/http: get does not work Apr 20, 2018
@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 20, 2018
@myitcv
Copy link
Member

myitcv commented Apr 20, 2018

Closing per:

Please see the Questions wiki page; it has a list of good places for asking questions. Thanks!

@myitcv myitcv closed this as completed Apr 20, 2018
@agnivade
Copy link
Contributor

I was thinking how to categorize this. This wasn't technically a question per-se. OP raised an issue which wasn't working in his system. While it was clear that this cannot be a bug in Go because of the simplicity of the issue, I think it warranted a bit more than simply closing it.

@myitcv
Copy link
Member

myitcv commented Apr 20, 2018

Apologies @agnivade (and @yyq2013) will re-open pending your update.

@myitcv myitcv reopened this Apr 20, 2018
@yyq2013
Copy link
Author

yyq2013 commented Apr 20, 2018

But same code works fine on linux OS.

@adamdecaf
Copy link
Contributor

adamdecaf commented Apr 20, 2018

@yyq2013 I'm not seeing this work on Go 1.10.1 in a docker image. With or without modifying http.DefaultClient.Transport. I don't have windows handy right now.

root@0e7d30ea69a8:/go# go run test.go 
2018/04/20 15:05:04 Get github.com: unsupported protocol scheme ""
exit status 1

root@0e7d30ea69a8:/go# go version
go version go1.10.1 linux/amd64

@yyq2013
Copy link
Author

yyq2013 commented Apr 20, 2018

@adamdecaf
why do you remove the scheme?
res, err:= http.Get("**https://**www.github.com/")

my linux:
[root@iZ2zef032vfaf0fdq8tcbuZ src]# go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/data/code/"
GORACE=""
GOROOT="/root/data/go"
GOTMPDIR=""
GOTOOLDIR="/root/data/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build220856888=/tmp/go-build"

[root@iZ2zef032vfaf0fdq8tcbuZ src]# cat test.go
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))

}
[root@iZ2zef032vfaf0fdq8tcbuZ src]# go run test.go
html content text printed here

@adamdecaf
Copy link
Contributor

adamdecaf commented Apr 20, 2018

@yyq2013 Your example had it removed when you posted originally.

@yyq2013
Copy link
Author

yyq2013 commented Apr 20, 2018

@adamdecaf maybe, I was updating it then

@agnivade agnivade added this to the Go1.11 milestone Apr 20, 2018
@agnivade
Copy link
Contributor

@yyq2013 - It seems like a system specific issue to me. Do you have access to another windows system ? Can you do a curl -O https://github.com and check ?

@yyq2013
Copy link
Author

yyq2013 commented Apr 20, 2018

@agnivade
C:\WINDOWS\system32>curl -O https://www.github.com
curl: Remote file name has no length!
curl: try 'curl --help' or 'curl --manual' for more information

It's strange, on another win10 it works.

@agnivade
Copy link
Contributor

Sorry, there has to be an path for -O. Try curl -o file https://github.com

@JoshVarga
Copy link

I just tested your sample (with DefaultClient commented out as well as not commented), and got back the entire web page correctly both times.
I am running Microsoft Windows 10 Pro build 16299 (64-bit OS, x64-based processor)
go version go1.10.1 windows/amd64

I think maybe the original code was just missing the scheme as @adamdecaf mentioned.

@yyq2013
Copy link
Author

yyq2013 commented Apr 21, 2018

I found the reason, there is a global socks5 proxy on my win10 OS, the default transport use it by default.

Sorry for wasting your time, everyone here.
I will be more careful before post a bug.
Thanks for your patient guide, everyone.

Please close it.

@golang golang locked and limited conversation to collaborators Apr 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

6 participants