亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

gin-gonic 支持是否收到請求?

gin-gonic 支持是否收到請求?

Go
慕俠2389804 2023-06-26 15:05:14
我是 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 回答

?
牧羊人nacy

TA貢獻1862條經驗 獲得超7個贊

您正在尋找的功能不是Param(),而是Query().


查看完整回答
反對 回復 2023-06-26
  • 1 回答
  • 0 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號