我是 gin-gonic 框架的新手,我一直在尝试从 html 的 get 请求中添加的输入中读取值,但我无法读取我编写的值。当我提交请求时,浏览器发送此网址: http://localhost:3000/backend?name1=value1&name2=value2&name3=value3我一直在互联网上查找 gin-gonic 使用此 url 类型的地方,但我只发现它使用像这样的 url http://localhost:3000/backend/value1html代码:<!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title></head><body> <form method="GET" action="/backend"> <input id="store" name="name1" type="text"> <input id="razon" name="name2" type="text"> <input id="total" name="name3" type="text"> <input type="submit" value="submit"> </form></body></html>戈兰代码:package mainimport("net/http""fmt""github.com/gin-gonic/contrib/static""github.com/gin-gonic/gin" )func main(){router := gin.Default()router.Use(static.Serve("/",static.LocalFile("./views",true)))router.GET("/backend",func(c *gin.Context){ fmt.Println(c.Param("name1")) c.JSON(http.StatusOK, gin.H{ "name1" : c.Param("name1"), })})router.Run(":3000")}实际结果:{"name1":""}预期结果:{"name1":"value1"}
- 1 回答
- 0 关注
- 103 浏览
添加回答
举报
0/150
提交
取消