http块响应来自GO服务器
提供的服务器代码如下: func handlepost(w http.responsewriter,r *http.request){ w.header()。设置(“连接”,“ keep-alive”) w.header()。设置(“转移编码”,“块”) w.header()。set(“ x-content-type-options”,“ nosniff”) 股票:= time.newticker(time.second) go func(){ 对于t:= range ticker.c { io.writestring(W,“块”) fmt.println(“ tick”,t) } }() time.sleep(time.second * 5) ticker.stop() fmt.println(“完成:应返回内容长度:0此处”) w.header()。设置(“内容长度”,“ 0”) } solution
以解决问题:
Revised Code
import ( “ FMT” “ io” “日志” “ net/http” “时间” ) func main(){ http.handlefunc(“/”,func(w http.ResponseWriter,r *http.request){ Flusher,OK:= w。(http.flusher) 如果!好{ PANIC(“期望http.ResponseWriter成为http.flusher”) } w.header()。set(“ x-content-type-options”,“ nosniff”) 对于I:= 1; i verification 在服务器发送时,每个块将逐渐收到。[&& &&&&华免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3