我正在使用fasthttp在Go中处理GET请求。
此请求中的查询参数test为.%2A%2Ftoday%2F.%2A。
我使用POSTMAN创建请求,生成的URL是:
http://localhost:3000/apiname/?test=.%252A%252Ftoday%252F.%252Actx.QueryArgs().Peek("test")给了我.*/today/.*,而不是原来的.%2A%2Ftoday%2F.%2A
我知道我不能对请求URL进行部分编码/解码。有没有办法按原样获取原始参数?
发布于 2021-08-08 10:50:00
真的吗?我刚刚测试过了,我得到了你想要的结果。
这是最小的工作示例:
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这是Postman的回复:

https://stackoverflow.com/questions/62168120
复制相似问题