【发布时间】:2021-07-28 21:21:21
【问题描述】:
我正在尝试将响应转换为 golang 中的 json。
func receive(w http.ResponseWriter, r *http.Request) {
reqBody, _ := ioutil.ReadAll(r.Body)
json.NewEncoder(w).Encode(string(reqBody))
println(string(reqBody))
func handleR() {
http.HandleFunc("/", receive)
log.Fatal(http.ListenAndServe(":30000", nil))
}
func main() {
handleR()
}
我的目标是有一个端点以 json 格式显示此响应。
【问题讨论】:
标签: http go mux ioutils encoding-json-go