所以,我想的东西基础上,例如这里在我的代码,并没有得到数据,但没有任何错误。代码是: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 关注
- 174 浏览
添加回答
举报
0/150
提交
取消