第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

JSON 解碼器不適用于 http 請(qǐng)求正文

JSON 解碼器不適用于 http 請(qǐng)求正文

Go
開(kāi)滿天機(jī) 2021-09-13 19:56:26
我開(kāi)始瘋狂地試圖讓 Go 解碼這個(gè) json 請(qǐng)求正文。這是一個(gè)示例請(qǐng)求:curl -X POST -d "{\"username\":\"foo\", \"password\":\"bar\"}" http://localhost:3000/users這是我的處理程序:mux.HandleFunc("/users", func(rw http.ResponseWriter, req *http.Request) {        var body struct {            username string            password string        }        // buf := make([]byte, req.ContentLength)        // req.Body.Read(buf)        // fmt.Println(string(buf))        //        // The above commented out code will correctly print:        // {"username":"foo", "password":"bar"}        err := json.NewDecoder(req.Body).Decode(&body)        if err != nil {            rw.WriteHeader(http.StatusNotAcceptable)            return        }        fmt.Printf("%+v\n", body)        // prints -> {username: password:}})就像評(píng)論所暗示的那樣,我可以驗(yàn)證這req.Body確實(shí)是正確的——但無(wú)論出于何種原因,json.NewDecoder(req.Body).Decode(&body)永遠(yuǎn)不會(huì)填寫body.任何幫助將不勝感激!
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 194 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)