英文:
Golang http server got two remote ports from one request
问题
我正在使用OSX 10.11.3的Macbook Pro进行工作,Golang版本为1.5。
以下是我的测试代码:
package main
import (
"net/http"
"fmt"
)
func main() {
http.HandleFunc("/", processGET)
c := &http.Server{
Addr: ":8080",
}
c.ListenAndServe()
}
func processGET(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.RemoteAddr)
}
预期结果应该在命令行屏幕上打印出客户端的IP和请求端口。
然而,每次我连接到HTTP服务器(分别在iPhone和Macbook上使用Chrome进行测试),我都会得到两条记录,IP相同(当然是同一个请求),但端口不同(请求的端口),像这样:
192.168.11.2:53061
192.168.11.2:53062
这是否意味着客户端同时发起了两个请求?我搜索了关于HTTP协议请求信息的资料,但仍然不清楚。
谢谢!
英文:
I'm working on a Macbook Pro with OSX 10.11.3, and the Golang version is 1.5,
following is my testing code
package main
import (
"net/http"
"fmt"
)
func main(){
http.HandleFunc("/", processGET)
c := &http.Server{
Addr: ":8080",
}
c.ListenAndServe()
}
func processGET(w http.ResponseWriter, r *http.Request){
fmt.Println(r.RemoteAddr)
}
The expected result should print the ip and the request port of the client on the command line screen,
however, each time I connected to the http server(testing with Chrome on iPhone and Macbook separately), I got two records with same ip(same request, of course) and different ports(requesting port), like this,
192.168.11.2:53061
192.168.11.2:53062
Does that mean the client initiate two requests at one time?
I searched about the http protocol request information but still have no idea.
Thanks!
答案1
得分: 0
你的浏览器正在寻找一个favicon.ico并发起了两个请求。尝试使用curl命令,你将只会得到一个请求。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论