当前位置:网站首页>Golang: go get url and form attribute value
Golang: go get url and form attribute value
2022-08-01 07:04:00 【ZzzWClock】
go获取urlAnd the form attribute values
一.前言
This section will be used tonet/http包开启web服务,获取request请求, The following router method can integrate globalhandle处理器,In order to make the article simplify,So in the image block of code,只更新handleInside the processor execution logic
package main
import (
"fmt"
"net/http"
)
// 处理器
func handle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "访问的path路径是: ", r.URL.Path)
}
func main() {
// 路由器
http.HandleFunc("/", handle)
// 开启server服务
http.ListenAndServe(":8081", nil)
}
二.示例
- 获取访问url的path路径

// 处理器
func handle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "访问的path路径是: ", r.URL.Path)
}
- 获取访问url的param参数值

// 处理器
func handle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "访问的path路径是: ", r.URL.Path)
fmt.Fprintln(w, "访问的param参数是: ", r.URL.RawQuery)
}
- 获取访问url单个的param参数值

// 处理器
func handle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "访问的path路径是: ", r.URL.Path)
fmt.Fprintln(w, "访问的param参数是: ", r.URL.RawQuery)
fmt.Fprintln(w, "访问的method是: ", r.Method)
// 注意FormValue 可以获取get参数还有post参数
fmt.Fprintln(w, fmt.Sprintf("admin值: %s, age值: %s", r.FormValue("admin"), r.FormValue("age")))
}
- 获取post请求参数值

// 处理器
func handle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "访问的path路径是: ", r.URL.Path)
fmt.Fprintln(w, "访问的param参数是: ", r.URL.RawQuery)
fmt.Fprintln(w, "访问的method是: ", r.Method)
// 注意FormValue 可以获取get参数还有post参数
fmt.Fprintln(w, fmt.Sprintf("admin值: %s, age值: %s", r.FormValue("admin"), r.FormValue("age")))
// PostFormValue 只会获取post传递过来的参数
fmt.Fprintln(w, fmt.Sprintf("username值: %s, age值: %s", r.PostFormValue("username"), r.PostFormValue("age")))
}
边栏推荐
- Dart exception details
- Golang: go to connect and use mysql
- Matlab simulink particle swarm optimization fuzzy pid control motor pump
- Solve the problem of page flicker caused by browser scroll bars
- Windows taskbar icon abnormal solution
- 史上超强最常用SQL语句大全
- 数据湖:数据同步工具NiFi
- 【南瓜书ML】(task4)神经网络中的数学推导(更新ing)
- rhcsa 第三次
- LeetCode 0149. Maximum number of points on a line
猜你喜欢

I have three degrees, and I have five faces. I was "confessed" by the interviewer, and I got an offer of 33*15.

Fist game copyright-free music download, League of Legends copyright-free music, can be used for video creation, live broadcast

支付宝如何生成及配置公钥证书

Image lossless compression software which works: try completely free JPG - C image batch finishing compression reduces weight tools | latest JPG batch dressing tools download

戴尔PowerEdge服务器R450 RAID配置步骤

How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos

crypto-js使用

Matlab simulink particle swarm optimization fuzzy pid control motor pump

阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外

NIO programming
随机推荐
Offer刷题——1
Matlab simulink particle swarm optimization fuzzy pid control motor pump
Compare two objects are the same depth
Windows taskbar icon abnormal solution
ORACLE modify another user package (package)
JVM:运行时数据区-PC寄存器(程序计数器)
Golang:go获取url和表单属性值
More than 2022 cattle guest school game 4 yue
Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
Srping bean in the life cycle
Leetcode第 304 场周赛
MATLAB程序设计与应用 2.5 MATLAB运算
如何使用Photoshop合成星轨照片,夜空星轨照片后期处理方法
表的创建、修改与删除
Why is the lightweight VsCode used more and more?Why eat my C drive 10G?How to Painlessly Clean VsCode Cache?Teach you how to lose weight for C drive
How JS works
轻量级的VsCode为何越用越大?为什么吃了我C盘10G?如何无痛清理VsCode缓存?手把手教你为C盘瘦身
sum of special numbers
安装SQL Server详细教程
Solve the problem of page flicker caused by browser scroll bars