首页 > 其他分享 >Gin postform 接参数数据参数

Gin postform 接参数数据参数

时间:2023-03-14 16:22:05浏览次数:21  
标签:engine http form postform ctx formDate 参数 gin Gin

如下

服务端代码

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

标签:engine,http,form,postform,ctx,formDate,参数,gin,Gin
From: https://www.cnblogs.com/guanchaoguo/p/17215320.html

相关文章