【发布时间】:2020-09-23 15:47:11
【问题描述】:
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"))
}
}
我使用 ASIhttprequst 发送一个来自,像这样。
[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"];
我用 req.FormValue("userid") 得到一个空值
发生了什么?以及如何解决?
【问题讨论】:
-
只是在黑暗中拍摄 - 也许您只是混淆了 PostValue 和 PostKey?
-
转储 HTTP 请求