HTTP服务器仅从浏览器提供“/”页面。

huangapple go评论90阅读模式
英文:

HTTP server only serves "/" from browser

问题

我基本上是将这个链接中的示例代码复制粘贴到了一个网页服务器中:http://thenewstack.io/building-a-web-server-in-go/

我在这里发布了代码:
http://play.golang.org/p/RvEr7E-v9q

我运行了服务器,并在浏览器中输入了"localhost:8080",这样就会像预期的那样调用hello(w,r)处理程序。但是,当我尝试从浏览器中输入"localhost/stuff:8080"时,它甚至不会调用ServeHTTP(w http.ResponseWriter, r *http.Request)

我在这里到底做错了什么愚蠢的事情?

谢谢

英文:

I basically cut and pasted the example to make a web server from this link: http://thenewstack.io/building-a-web-server-in-go/

Posted the code here:
http://play.golang.org/p/RvEr7E-v9q

I run the server and put in browser "localhost:8080" and this calls the hello(w,r) handler as expected. When trying from browser "localhost/stuff:8080" it doesn't even call the ServeHTTP(w http.ResponseWriter, r *http.Request)

What fundamentally ridiculous thing am I doing wrong here?

Thanks

答案1

得分: 5

是的。您没有使用有效的URL。端口号应该在路径之前。下面的方案描述了一个URL。您应该使用localhost:8080/whatever/the/path/is,而不是localhost/some/path/this/should/never/work/because/its/not/valid:8080

方案:[//[user:password@]host[:port]][/]path[?query][#fragment]

英文:

Yes. You're not using a valid url. The port number comes before the path. The scheme below describes a url. You hsould have localhost:8080/whatever/the/path/is and never localhost/some/path/this/should/never/work/because/its/not/valid:8080

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

huangapple
  • 本文由 发表于 2016年1月1日 02:53:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/34550557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定