macos - Golang http 服务器从一个请求中获得了两个远程端口

标签 macos http go 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协议(protocol)请求的资料,还是没有头绪。

谢谢!

最佳答案

您的浏览器正在寻找发起​​两个请求的 favicon.ico。尝试使用 curl,您将收到一个请求。

wireshark output

关于macos - Golang http 服务器从一个请求中获得了两个远程端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35501440/

相关文章:

macos - bash 错误 : Cannot find/Library/. ..../setclasspath.sh,但它在那里

macos - 在特定情况下显示或不显示关闭窗口的警报

csv - 同时创建和写入两个CSV golang

go - 如何指定多个返回值的类型

go - 将数组转换为 csv

swift - updateLayer() 上下文

java - 在java中使用登录加载网页

node.js http 模块 http.createServer 是如何工作的?

java - 截击请求太慢

c - 为什么 fflush(stdin) 不删除缓冲区 (stdin)