英文:
Send http GET command from Telnet
问题
我有一个简单的程序:
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/users", UsersHandler)
fmt.Println("Starting server...")
http.ListenAndServe(":8181", nil)
}
func UsersHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Users")
}
如果我从浏览器发送一个 GET
命令:http://localhost:8181
,我可以看到打印出来的消息是 "Users",但是如果我从 telnet 连接,当我执行以下命令时没有消息被打印出来:
telnet 127.0.0.1 8181
GET /users HTTP/1.1
有任何想法为什么会这样?
英文:
I have this simple program:
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/users", UsersHandler)
fmt.Println("Starting server...")
http.ListenAndServe(":8181", nil)
}
func UsersHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Users")
}
If I send a GET
command from the browser: http://localhost:8181
I can see the message "Users" printed, but If I connect from telnet no message is printed when I do:
telnet 127.0.0.1 8181
GET /users HTTP/1.1
Any idea why is that ?
答案1
得分: 5
你需要输入第二个回车符,表示头部块的结束。
英文:
You need to enter a second carriage return, which signifies the end of the headers block.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论