我有一个where应用程序,其中的代码如下:
func handler (w res, r req) {
if req.Method == POST {
// create html form 2 with a submit button2
return ;
}
// create html form 1 with a submit button1
return
}
func main() {
handle("/", handler)
}
现在,根/已注册到处理程序func。在第一个请求(GET)中,我创建了一个表单并将其发送给用户。如果
我的网页"mywebpage.php“是通过”someotherpage.php“中的”GET“得到的:
// In someotherpage.php -- go to mywebpage.php and display the form:
window.location = "mywebpage.php?someVariable=" + theVariable;
我在"mywebpage.php“中的处理方式如下:
THIS IS THE 'GET' HANDLER for the form IN "mywebpage.php
为了确保所有表单提交和所有提交到服务器的数据都不是通过GET提交的,我找到了这段代码
if(request.method == 'GET') {
response.sendError(405)
} else {
// the rest of the delete action goes here
}
我们可以将其应用于所有控制器扩展的基本控制器中,这样代码就不会在任何地方重复。上面的方法检查现有的方法,我想知道是否有一种方法可以在整个应用程序中将该方法设置为POST,就像所有表单和所有提交的数据都应该由POST提交一样。我用来设置这个的任