如何使用GO&#x27的NET/HTTP检查是否以帖子表格中存在值?

发布于 2025-02-07 19:37:07 字数 421 浏览 2 评论 0原文

根据文档

PostFormValue返回帖子,补丁或PUT请求主体的命名组件的第一个值。 URL查询参数被忽略。 如有必要 并忽略这些功能返回的任何错误。 如果不存在键,则postformvalue返回空字符串。

因此,函数request.postformvalue(键字符串)字符串键>键 时返回一个空字符串在邮局中不存在,而是存在于其存在且价值为空的时。

我只能检查钥匙是否在邮局中,无论其价值如何?

According to the documentation:

PostFormValue returns the first value for the named component of the POST, PATCH, or PUT request body.
URL query parameters are ignored.
PostFormValue calls ParseMultipartForm and ParseForm if necessary
and ignores any errors returned by these functions.
If key is not present, PostFormValue returns the empty string.

So the function Request.PostFormValue(key string) string returns an empty string when key does not exist in the POST body, but also when it exists and its value is empty.

How can I only check if the key is in the POST body, regardless of its value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光的暖冬 2025-02-14 19:37:07

解析表单,然后检查是否键是在发布表单

req.ParseForm()
hasKey := req.PostForm.Has("key")

Parse the form and then check to see if the key is set in the post form.

req.ParseForm()
hasKey := req.PostForm.Has("key")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文