所以,我想的東西基礎上,例如這里在我的代碼,并沒有得到數據,但沒有任何錯誤。代碼是:import ( "io" "fmt" "net/http" "encoding/json")type Credential struct { username string `json:"username"` password string `json:"password"`}func login(res http.ResponseWriter, req *http.Request) { if req.Method == "POST" { cred := Credential{} err := json.NewDecoder(req.Body).Decode(&cred) if err != nil { panic("can't decode") } fmt.Println("credentials: " + cred.username + " , " + cred.password) }}我測試curl -X POST -H "Accept: application/json" --data "{\"username\":\"x\",\"password\":\"y\"}" 127.0.0.1:8000/login -一世服務器打印出:證書: ,為什么 cred.username 和 cred.password 中沒有任何內容?
- 1 回答
- 0 關注
- 192 瀏覽
添加回答
舉報
0/150
提交
取消