提前致谢.
这是代码http://play.golang.org/p/aZxPCcRAVV
package mainimport ( "HTML/template" "log" "net/http")func rootHandler(w http.ResponseWriter,r *http.Request) { t,_ := template.New("form.HTML").Parse(form) t.Execute(w,"")}func formHandler(w http.ResponseWriter,r *http.Request) { log.Println(r.Form) rootHandler(w,r)}func main() { http.HandleFunc("/",rootHandler) http.HandleFunc("/login",formHandler) http.ListenAndServe("127.0.0.1:9999",nil)}var form = `<h1>Login</h1><form action="/login" method="POST"><div><input name="username" type="text"></div><div><input type="submit" value="Save"></div></form>`解决方法 看来你需要先调用ParseForm.从go文档
// Form contains the parsed form data,including both the URL// fIEld's query parameters and the POST or PUT form data.// This fIEld is only available after ParseForm is called.// The http clIEnt ignores Form and uses Body instead.Form url.Values
和一些代码让你的例子工作.
func formHandler(w http.ResponseWriter,r *http.Request) { err := r.ParseForm() if err != nil { //handle error http.Error() for example return } log.Println(r.Form) rootHandler(w,r)}总结
以上是内存溢出为你收集整理的在表单提交时,请 – 请求.Post数组为空全部内容,希望文章能够帮你解决在表单提交时,请 – 请求.Post数组为空所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)