go - 如何在没有 URL 解码的情况下读取 fasthttp 中的查询参数
问题描述
我正在使用fasthttpGET
处理Go 中的请求。
此请求中的查询参数test
是.%2A%2Ftoday%2F.%2A
。
我正在使用 POSTMAN 创建请求,生成的 URL 是:
http://localhost:3000/apiname/?test=.%252A%252Ftoday%252F.%252A
ctx.QueryArgs().Peek("test")
给了我 .*/today/.*
而不是原来的.%2A%2Ftoday%2F.%2A
我知道我无法对请求 URL 进行部分编码/解码。有没有办法按原样获取原始参数?
解决方案
你确定吗?我刚刚测试了它,我得到了你想要的结果。
这是最小的工作示例:
package main
import (
"fmt"
"log"
"github.com/fasthttp/router"
"github.com/valyala/fasthttp"
)
func Test(ctx *fasthttp.RequestCtx) {
ctx.Response.SetBodyString(string(ctx.QueryArgs().Peek("test")))
fmt.Println(string(ctx.QueryArgs().Peek("test")))
}
func main() {
r := router.New()
r.GET("/test", Test)
log.Fatal(fasthttp.ListenAndServe("127.0.0.1:8080", r.Handler))
}
这是 GET 请求后的命令行输出:
$ go run main.go
.%2A%2Ftoday%2F.%2A
这是邮递员的回应:
推荐阅读
- javascript - 如何在没有 javascript 任何元素注入的情况下将图标放置到每个 jquery ui 自动完成
- typescript - Typescript 推断的对象字面量类型扩展如何工作?
- ruby - 如何将条件的多行形式转换为后缀形式?
- ruby - 将数组值存储到 csv 列中
- jquery - 到达窗口底部时拉伸网格
- javascript - .getElementByClassName 不可靠。我还能如何指向没有 ID 的 HTML 元素?
- react-native - 反应原生新鲜项目错误
- php - 如何将电子邮件发送到 html 表单中的特定选择?
- reactjs - 解决 onClick 事件在 material-ui 中的“Enter Key”按下时被触发两次(错误)
- cordova - UWP 导入第三方代码签名证书失败