Gin postform 接参数数据参数

如下

服务端代码

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	engine := gin.Default()
	engine.POST("/data", handData)

	engine.Run(":9000")
}

func handData(ctx *gin.Context) {
	formDate := make(map[string]string)
	err := ctx.ShouldBind(&formDate)
	fmt.Println(formDate)
	if err != nil {
		ctx.String(http.StatusNotFound, "绑定form失败")
	} else {
		ctx.String(http.StatusOK, "绑定form成功")
	}
}

http

#####
POST localhost:9000/data
Content-Type: application/x-www-form-urlencoded

username[1][0]=yudaoyuanma&password[1][3]=123456
posted @ 2023-03-14 16:13  vx_guanchaoguo0  阅读(32)  评论(0编辑  收藏  举报