如果 url 查询参数没有值,它是否有效? [英] Is a url query parameter valid if it has no value?

查看:27
本文介绍了如果 url 查询参数没有值,它是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://example.com/foo?bar 这样的网址是否有效?

Is a url like http://example.com/foo?bar valid?

我正在寻找一个链接,指向官方的某种说法.一个简单的是/否答案或轶事证据都无法解决问题.

I'm looking for a link to something official that says one way or the other. A simple yes/no answer or anecdotal evidence won't cut it.

推荐答案

  • 对 URI RFC 有效
  • 您的服务器端框架/代码可能可以接受
  • URI RFC 不要求查询字符串的格式.尽管公认查询字符串通常会携带名称-值对,但并非必须如此(例如,它通常会包含另一个 URI).

    The URI RFC doesn't mandate a format for the query string. Although it is recognized that the query string will often carry name-value pairs, it is not required to (e.g. it will often contain another URI).

    3.4.查询

    查询组件包含非分层数据,以及路径组件中的数据(第 3.3 节),用于识别URI 方案和命名权限范围内的资源(如果有的话)....

    The query component contains non-hierarchical data that, along with data in the path component (Section 3.3), serves to identify a resource within the scope of the URI's scheme and naming authority (if any). ...

    ... 但是,作为查询组件通常用于以以下形式携带识别信息键=值"对和一个经常使用的值是对另一个 URI,...

    ... However, as query components are often used to carry identifying information in the form of "key=value" pairs and one frequently used value is a reference to another URI, ...

    HTML 确定提交的表单通过 HTTP GET 应该将表单值编码为?key1=value1&key2=value2..."(正确编码)形式的名称-值对.查询字符串的解析取决于服务器端代码(例如 Java servlet 引擎).

    HTML establishes that a form submitted via HTTP GET should encode the form values as name-value pairs in the form "?key1=value1&key2=value2..." (properly encoded). Parsing of the query string is up to the server-side code (e.g. Java servlet engine).

    您不知道您使用的是哪个服务器端框架(如果有),但您的服务器端框架可能会假定查询字符串将始终以名称-值对形式存在,并且可能会阻塞查询字符串不是那种格式(例如 ?bar).如果它是您自己的自定义代码来解析查询字符串,您只需确保您处理该查询字符串格式.如果它是一个框架,您需要查阅您的文档或简单地测试它以了解它是如何处理的.

    You don't identify what server-side framework you use, if any, but it is possible that your server-side framework may assume the query string will always be in name-value pairs and it may choke on a query string that is not in that format (e.g. ?bar). If its your own custom code parsing the query string, you simply have to ensure you handle that query string format. If its a framework, you'll need to consult your documentation or simply test it to see how it is handled.

    这篇关于如果 url 查询参数没有值,它是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆