gin post dataparameters_golang--ginは投稿の本文パラメーターを取得します

次のコンテンツはhttps://blog.csdn.net/weixin_36344862/article/details/111932206から複製されてい ます。

上記のように、送信後のデータにはいくつかの形式があり、フォームとストリームが最も一般的に使用されます。特にプログラムでhttpcを使用する

package main

import (
	"fmt"

	"net/http"

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

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

	router.POST("/events", events)

	router.Run(":5000")

}

func events(c *gin.Context) {
	buf := make([]byte, 1024)

	n, _ := c.Request.Body.Read(buf)

	fmt.Println(string(buf[0:n]))

	resp := map[string]string{"hello": "world"}

	c.JSON(http.StatusOK, resp)

	/*post_gwid := c.PostForm("name")
	  fmt.Println(post_gwid)*/

}

lientsは通常、ストリームを介して送信されると見なされます。phpでは、php:// inputを介して取得されます。ginでは、c.Request.Body.Read(buf)を渡すことができます。具体的なコードは次のとおりです。

おすすめ

転載: blog.csdn.net/pyf09/article/details/115134942