当前位置:网站首页>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")))
}
边栏推荐
- 企业员工人事管理系统(数据库课设)
- 深度比较两个对象是否相同
- Three aspects of Ali: How to solve the problem of MQ message loss, duplication and backlog?
- 我的创作纪念日
- I have three degrees, and I have five faces. I was "confessed" by the interviewer, and I got an offer of 33*15.
- MVVM项目开发(商品管理系统一)
- 「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader
- 小白的0基础教程SQL: 什么是SQL 01
- LeetCode Question of the Day (309. Best Time to Buy and Sell Stock with Cooldown)
- 自制一款远程控制软件——VeryControl
猜你喜欢

Introduction to the basic principles, implementation and problem solving of crawler

「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader

dbeaver连接MySQL数据库及错误Connection refusedconnect处理

"By sharing" northwestern university life service | | bytes a second interview on three sides by HR

MVVM project development (commodity management system 1)

企业员工人事管理系统(数据库课设)

MySQL row locks and gap locks

特殊的日子,值得纪念

NIO编程

仿牛客网项目总结
随机推荐
LeetCode Question of the Day (309. Best Time to Buy and Sell Stock with Cooldown)
Vim简介
支付宝如何生成及配置公钥证书
选择排序—直接选择排序和堆排序
return; represents meaning
curl (7) Failed connect to localhost8080; Connection refused
Golang:go开启web服务
Flip letters using string container
matlab simulink 粒子群优化模糊pid控制的电机泵
小程序通过云函数操作数据库【使用get取数据库】
Self-made a remote control software - VeryControl
uva12326
小白的0基础教程SQL: 关系数据库概述 02
NUMPY
【一句话攻略】彻底理解JS中的回调(Callback)函数
Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
R语言使用gt包和gtExtras包优雅地、漂亮地显示表格数据:gtExtras包的pad_fn函数与gt::fmt函数一起用于填充包含数值的特定列、对数据列的数值进行十进制对齐(从小数点对齐)
小白的0基础教程SQL: 什么是SQL 01
matlab wind speed model wavelet filtering
Golang:go获取url和表单属性值