解析Go的http.Request参数

单行、唯一 0     2339      服务端   0     0
GO、GoLang

地址:

http://127.0.0.1:9099/api/user/bb?name=唯一&age=30


get结果:


welcome weigo
r.URL:  /api/user/bb?name=%E5%94%AF%E4%B8%80&age=30
r.URL.Path:  /api/user/bb
r.URL.Host:  
r.URL.User:  
r.URL.ForceQuery:  false
r.URL.Fragment:  
r.URL.Opaque:  
r.URL.RawFragment:  
r.URL.RawPath:  
r.URL.RawQuery:  name=%E5%94%AF%E4%B8%80&age=30
r.URL.Scheme:  
r.URL.Query():  map[age:[30] name:[唯一]]
r.URL.EscapedFragment():  
r.URL.Hostname():  
r.URL.IsAbs():  false
r.URL.Port():  
r.URL.String():  /api/user/bb?name=%E5%94%AF%E4%B8%80&age=30
-------------------------
r.Host:  127.0.0.1:9099
r.Body:  {}
r.Method:  GET
r.Form:  map[]
r.ContentLength:  0
r.Header:  map[Accept:[text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9] Accept-Encoding:[gzip, deflate, br] Accept-Language:[zh-CN,zh;q=0.9] Cache-Control:[max-age=0] Connection:[keep-alive] Sec-Fetch-Dest:[document] Sec-Fetch-Mode:[navigate] Sec-Fetch-Site:[none] Sec-Fetch-User:[?1] Upgrade-Insecure-Requests:[1] User-Agent:[Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36]]
r.MultipartForm:  
r.PostForm:  map[]
r.RemoteAddr:  127.0.0.1:61554
r.RequestURI:  /api/user/bb?name=%E5%94%AF%E4%B8%80&age=30
r.TransferEncoding:  []
r.Context():  context.Background.WithValue(type *http.contextKey, val ).WithValue(type *http.contextKey, val 127.0.0.1:9099).WithCancel.WithCancel
r.FormValue("name"):  唯一
r.ParseForm():  
----------------------------
=============================


get地址:

http://127.0.0.1:9099/api/user/login

 结果:

welcome weigo
r.URL:  /api/user/login
r.URL.Path:  /api/user/login
r.URL.Host:  
r.URL.User:  
r.URL.ForceQuery:  false
r.URL.Fragment:  
r.URL.Opaque:  
r.URL.RawFragment:  
r.URL.RawPath:  
r.URL.RawQuery:  
r.URL.Scheme:  
r.URL.Query():  map[]
r.URL.EscapedFragment():  
r.URL.Hostname():  
r.URL.IsAbs():  false
r.URL.Port():  
r.URL.String():  /api/user/login
-------------------------
r.Host:  127.0.0.1:9099
r.Body:  {}
r.Method:  GET
r.Form:  map[]
r.ContentLength:  0
r.Header:  map[Accept:[text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9] Accept-Encoding:[gzip, deflate, br] Accept-Language:[zh-CN,zh;q=0.9] Connection:[keep-alive] Sec-Fetch-Dest:[document] Sec-Fetch-Mode:[navigate] Sec-Fetch-Site:[none] Sec-Fetch-User:[?1] Upgrade-Insecure-Requests:[1] User-Agent:[Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36]]
r.MultipartForm:  
r.PostForm:  map[]
r.RemoteAddr:  127.0.0.1:61554
r.RequestURI:  /api/user/login
r.TransferEncoding:  []
r.Context():  context.Background.WithValue(type *http.contextKey, val ).WithValue(type *http.contextKey, val 127.0.0.1:9099).WithCancel.WithCancel
r.FormValue("name"):  
r.ParseForm():  
----------------------------
=============================


地址:

http://127.0.0.1:9099/api/user/login

post结果:

welcome weigo
r.URL:  /api/user/login
r.URL.Path:  /api/user/login
r.URL.Host:  
r.URL.User:  
r.URL.ForceQuery:  false
r.URL.Fragment:  
r.URL.Opaque:  
r.URL.RawFragment:  
r.URL.RawPath:  
r.URL.RawQuery:  
r.URL.Scheme:  
r.URL.Query():  map[]
r.URL.EscapedFragment():  
r.URL.Hostname():  
r.URL.IsAbs():  false
r.URL.Port():  
r.URL.String():  /api/user/login
-------------------------
r.Host:  127.0.0.1:9099
r.Body:  {}
r.Method:  POST
r.Form:  map[]
r.ContentLength:  0
r.Header:  map[Accept:[*/*] Content-Length:[0] Content-Type:[application/x-www-form-urlencoded]]
r.MultipartForm:  
r.PostForm:  map[]
r.RemoteAddr:  127.0.0.1:50306
r.RequestURI:  /api/user/login
r.TransferEncoding:  []
r.Context():  context.Background.WithValue(type *http.contextKey, val ).WithValue(type *http.contextKey, val 127.0.0.1:9099).WithCancel.WithCancel
r.FormValue("name"):  
r.ParseForm():  
----------------------------
=============================


地址:

http://127.0.0.1:9099/api/user/login?name=唯一&sex=1


post结果:

welcome weigo
r.URL:  /api/user/login?name=唯一&sex=1
r.URL.Path:  /api/user/login
r.URL.Host:  
r.URL.User:  
r.URL.ForceQuery:  false
r.URL.Fragment:  
r.URL.Opaque:  
r.URL.RawFragment:  
r.URL.RawPath:  
r.URL.RawQuery:  name=唯一&sex=1
r.URL.Scheme:  
r.URL.Query():  map[name:[唯一] sex:[1]]
r.URL.EscapedFragment():  
r.URL.Hostname():  
r.URL.IsAbs():  false
r.URL.Port():  
r.URL.String():  /api/user/login?name=唯一&sex=1
-------------------------
r.Host:  127.0.0.1:9099
r.Body:  {}
r.Method:  POST
r.Form:  map[]
r.ContentLength:  0
r.Header:  map[Accept:[*/*] Content-Length:[0] Content-Type:[application/x-www-form-urlencoded]]
r.MultipartForm:  
r.PostForm:  map[]
r.RemoteAddr:  127.0.0.1:50315
r.RequestURI:  /api/user/login?name=唯一&sex=1
r.TransferEncoding:  []
r.Context():  context.Background.WithValue(type *http.contextKey, val ).WithValue(type *http.contextKey, val 127.0.0.1:9099).WithCancel.WithCancel
r.FormValue("name"):  唯一
r.ParseForm():  
----------------------------
=============================





captcha
忘记密码? 注册
第三方登录
微信赞赏
支付宝赞赏