dongli7870
2016-06-16 15:25
浏览 553
已采纳

ResponseWriter.Write和io.WriteString有什么区别?

I've seen three ways of writing content to HTTP response:

func Handler(w http.ResponseWriter, req *http.Request) {
    io.WriteString(w, "blabla.
")
}

And:

func Handler(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("blabla
"))
}

Also there's:

fmt.Fprintf(w, "blabla")

What's the difference between them? Which one is preferred to use?

图片转代码服务由CSDN问答提供 功能建议

我已经看到了三种将内容写入HTTP响应的方式:

   func Handler(w http.ResponseWriter,req * http.Request){
 io.WriteString(w,“ blabla。
”)
} 
   
 
  

And:

  func Handler(w http.ResponseWriter,r * http.Request){
 w.Write([] byte(“ blabla 
”)  )
} 
   
 
 

也有:

  fmt.Fprintf(w,“ blabla”)
    
 
 

它们之间有什么区别? 首选使用哪一个?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题