From b9a4736b99564a570d1220d14f18e9656a1fa160 Mon Sep 17 00:00:00 2001 From: Noah <130611693+upupnoah@users.noreply.github.com> Date: Sun, 4 Feb 2024 01:01:18 +0800 Subject: [PATCH] Update map-as-querystring-or-postform.md Add commands that can be directly requested and modify "fmt" to "log". --- .../map-as-querystring-or-postform.md | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/content/en/docs/examples/map-as-querystring-or-postform.md b/content/en/docs/examples/map-as-querystring-or-postform.md index fa733e2ef..3f6ba0c52 100644 --- a/content/en/docs/examples/map-as-querystring-or-postform.md +++ b/content/en/docs/examples/map-as-querystring-or-postform.md @@ -3,11 +3,19 @@ title: "Map as querystring or postform parameters" draft: false --- -```sh -POST /post?ids[a]=1234&ids[b]=hello HTTP/1.1 -Content-Type: application/x-www-form-urlencoded +```shell +# POST /post?ids[a]=1234&ids[b]=hello HTTP/1.1 +POST /post?ids%5Ba%5D=1234&ids%5Bb%5D=hello HTTP/1.1 +Content-Type: application/x-www-form-urlencoded; charset=utf-8 -names[first]=thinkerou&names[second]=tianou +# names[first]=thinkerou&names[second]=tianou +names%5Bfirst%5D=thinkerou&names%5Bsecond%5D=tianou +``` +```shell +curl -X "POST" "http://localhost:8080/post?ids%5Ba%5D=1234&ids%5Bb%5D=hello" \ + -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \ + --data-urlencode "names[first]=thinkerou" \ + --data-urlencode "names[second]=tianou" ``` ```go @@ -19,13 +27,8 @@ func main() { ids := c.QueryMap("ids") names := c.PostFormMap("names") - fmt.Printf("ids: %v; names: %v", ids, names) + log.Printf("ids: %v; names: %v", ids, names) }) router.Run(":8080") } ``` - -```sh -ids: map[b:hello a:1234], names: map[second:tianou first:thinkerou] -``` -