gpt4 book ai didi

go - 如何从Golang的*fasthttp.Request获取header内容?

转载 作者:数据小太阳 更新时间:2023-10-29 03:23:15 28 4
gpt4 key购买 nike

As the title says , is there an api for that?

*fasthttp.Request.Header.key 

When I call the method with POSTMAN , I can't get the header content key as the above code . Why

最佳答案

您可能会惊讶地发现 fasthttp 不将请求 header 值存储为导出的 map[string]string,而是存储为未导出的 []byte将索引存储到。这显然是其性能优化之一。

您可以使用 Peek() 获取请求 header 值.

v := ctx.Request.Header.Peek("User-Agent")

请注意,此函数返回字节 slice ,因此您可能必须将其转换为字符串

sv := string(v)

关于go - 如何从Golang的*fasthttp.Request获取header内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49312187/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com