Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

golang http server,can't get post value

Tags:

http

go

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:@"[email protected]"];
[request setPostValue:@"pwd" forKey:@"fdsfdsfdkskfjhds"];
[request setRequestMethod:@"POST"];

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

what happend? and how to fix it?

like image 942
user1751912 Avatar asked Jun 03 '13 12:06

user1751912


1 Answers

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

like image 90
Neo Avatar answered Sep 27 '22 21:09

Neo