gin獲取post的body里的參數


例子

在map2中即可獲取 body中的參數

 

獲取方式,參見postman

 

 

//sign in
	authorized.POST("/signIn", func(context *gin.Context){
		buf := make([]byte, 1024)
		n, _ := context.Request.Body.Read(buf)
		
		for i := 0; i < n; i +=1 {
			if(buf[i] ==' ' || buf[i] == '\x00') {
				buf = append(buf[:i], buf[(i + 1):]...)
				n -= 1
			}
		}

		map2 := make(map[string]string)

		err = json.Unmarshal(buf[:n], &map2)
		fmt.Println(map2)

		t_nickName := map2["nickname"]
		t_password := map2["password"]
		
	})

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM