http.ResponseWriter的Flush

it2022-05-31  80

func handle(res http.ResponseWriter, req *http.Request) { fmt.Fprintf(res, "sending first line of data") sleep(10) fmt.Fprintf(res, "sending second line of data") }这样first data和second data都会最后同时传到客户端浏览器。但是我们的目的是为了能一有数据就先传给浏览器。所以: func handle(res http.ResponseWriter, req *http.Request) { fmt.Fprintf(res, "sending first line of data") res.(http.Flusher).Flush() sleep(10) fmt.Fprintf(res, "sending second line of data") }资料: https://stackoverflow.com/questions/19292113/not-buffered-http-responsewritter-in-golang

转载于:https://www.cnblogs.com/xiaouisme/p/7027536.html


最新回复(0)