英文:
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]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论