golang http server,can't get post value

2019-04-19 10:04发布

func login(rw http.ResponseWriter, req *http.Request) {
    req.ParseForm()

    if req.Method == "GET" {
        fmt.Fprintf(rw, "Error Method")
    } else {
        name := strings.TrimSpace(req.FormValue("userid"))
        fmt.Println("userid:", name)
        fmt.Println("pwd:", req.FormValue("pwd"))
        fmt.Fprintf(rw, "welcome back,%s", req.FormValue("userid"))
    }
}

and i using ASIhttprequst send a from,like this.

[self setRequest:[ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1:8080/login"]]];
[request setPostValue:@"userid" forKey:@"fdfs@jkjlf.cm"];
[request setPostValue:@"pwd" forKey:@"fdsfdsfdkskfjhds"];
[request setRequestMethod:@"POST"];

i got a null value with req.FormValue("userid")

what happend? and how to fix it?

标签: http go
8条回答
劫难
2楼-- · 2019-04-19 10:30

Try this buddy.

hope it will work as it works for me

r.FormValue("userid")
查看更多
男人必须洒脱
3楼-- · 2019-04-19 10:33

did you already test it with req.PostFormValue instead of req.FormValue ?

查看更多
登录 后发表回答