谷歌浏览器会触发两次Handler

package main

import (
	"io"
	"net/http"
	"strconv"
)

var count int = 0 

// handler
func firstPage(w http.ResponseWriter, r *http.Request) {
	count++
	io.WriteString(w, strconv.Itoa(count))
}

func main() {
	http.HandleFunc("/", firstPage)
	http.ListenAndServe(":8000", nil)
}

本来刷新页面应该1,2,3,4,5 ... 慢慢加的,但是用谷歌浏览器访问就是1,3,5,7,9。

用IE访问就是和预判一样1,2,3,4,5

如果访问是http.HandleFunc("/test", firstPage)就都正常

参考 https://www.oschina.net/question/1377982_163795

posted on 2020-09-08 00:27  longzhankunlun  阅读(370)  评论(0编辑  收藏  举报