烂翻译系列之Iris——API示例之Query和post 表单参数

Query and post form parameters  Query和post 表单参数

POST /post?id=a&id=b&id=c&name=john&name=doe&name=kataras
Content-Type: application/x-www-form-urlencoded
func main() {
    app := iris.Default()

    app.Post("/post", func(ctx iris.Context) {

        ids := ctx.URLParamSlice("id")
        names, err := ctx.PostValues("name")
        if err != nil {
            ctx.StopWithError(iris.StatusBadRequest, err)
            return
        }

        ctx.Writef("ids: %v; names: %v", ids, names)
    })
    app.Listen(":8080")
}
ids: [a b c], names: [john doe kataras]

 

 

  
posted @ 2021-12-13 16:25  菜鸟吊思  阅读(239)  评论(0)    收藏  举报