当前位置:网站首页>go : gin Urlencoded 格式

go : gin Urlencoded 格式

2022-07-23 10:20:00 IT工作者

代码:

package main

import (
    "github.com/gin-gonic/gin"
)

func main() {
    router := gin.Default()

    router.POST("/form_post", func(c *gin.Context) {
        message := c.PostForm("message")
        nick := c.DefaultPostForm("nick", "anonymous")

        c.JSON(200, gin.H{
            "status":  "posted",
            "message": message,
            "nick":    nick,
        })
    })
    router.Run(":8080")
}

运行程序

客户端测试

->curl  localhost:8080/form_post --form message=hello
{"message":"hello","nick":"anonymous","status":"posted"}

服务端日志

原网站

版权声明
本文为[IT工作者]所创,转载请带上原文链接,感谢
https://cloud.tencent.com/developer/article/2054817