1
我正在写一个使用web.go的小型应用程序,它具有一个提供表单的函数。如果表单无效,用户会被重定向到同一页:Web.go我该如何做http重定向?
func mypage(ctx *web.Context) {
if ctx.Request.Method == "GET" {
// show the form
} else if ctx.Request.Method == "POST" {
// redirection if the form is not valid:
ctx.Request.Method = "GET"
http.Redirect(ctx.ResponseWriter,
ctx.Request, "/mypage", http.StatusNotAcceptable)
return
}
}
这个方法奏效,有一点需要注意的是,当形式是无效的,它首先显示与被喜欢的文字"Not Acceptable"
页面/mypage
。如果表单无效,我怎样才能直接转到/mypage
?我怀疑它与http.StatusNotAcceptable
有关,但我不知道应该用什么替换它。