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