简体   繁体   中英

Golang http server got two remote ports from one request

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!

Your browser is looking for a favicon.ico initiating two requests. Try with curl and you will get one request.

Wireshark输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM