表单
本节演示查询字符串与表单一起提交,服务端数据解析
请求
发起请求如下
POST /post?id=1234&page=1 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
name=manu&message=this_is_great
应用
func main() {
app := iris.Default()
app.Post("/post", func(ctx iris.Context) {
id := ctx.URLParam("id")
page := ctx.URLParamDefault("page", "0")
name := ctx.FormValue("name")
message := ctx.FormValue("message")
// 或使用 `ctx.PostValue` ,它仅支持 POST, PUT 或 PATCH 谓词 HTTP 方法
app.Logger().Infof("id: %s; page: %s; name: %s; message: %s", id, page, name, message)
})
app.Run(iris.Addr(":8080"))
}
响应
id: 1234; page: 1; name: manu; message: this_is_great