URL路径参数使用案例 [英] URL Path Parameter Use Cases

查看:461
本文介绍了URL路径参数使用案例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当我想在URL参数,我想查询字符串。技术上,然而,它也可以将指定要在路径段的参数。因此,给一个URL是这样的:

Normally when I think of parameters in an URL, I think of the query string. Technically, however, it is also legal to specify parameters in the path segments. Thus given a URL like this:

http://www.a.com/frisbee/brand

这是合法的,而不是写:

It is legal to write this instead:

http://www.a.com/frisbee;color=red;size=small/brand;test=1

在实践中我从来没有看到这一点。什么框架,如果有的话,就利用这个?

In practice I never see this. What frameworks, if any, do make use of this?

我和后期ASP.NET MVC3的工作,我不知道它可以提取这些类型的参数。

I'm working with ASP.NET MVC3 of late, and I'm not sure it can extract these kinds of parameters.

推荐答案

许多现代的框架将支持指定变量作为路径段的一部分,在他们的网址解析系统。

Many modern framework will support specifying variables as part of a path segment, in their URL-parsing systems.

的Symfony(PHP)和Django的(Python)的会都支持这一点,也支持通过定期EX pressions从URL中提取值。

Symfony (PHP) and Django (Python) would both support this as they support extracting values from URLs via regular expressions.

一个显著不同的是,在查询字符串指定的参数通常可以以任何顺序,因为它们将通常被解析成一个字典状结构。这将不适用于参数的路径段。你当然可以自己分析他们进入一本字典,但我刚才提到的框架不会帮助你做到这一点。

One significant difference is that parameters specified in the query string can usually be in any order, because they will typically be parsed into a dictionary-like structure. That wouldn't apply to parameters in a path segment. You could of course parse them yourself into a dictionary, but the frameworks I just mentioned won't help you do that.

请注意,在技术上的参数的顺序是在HTTP URI显著反正,即两个URL其中参数(路径或查询字符串)分别以不同的顺序符合标准的比较,就必须假定他们可以引用不同的资源。

Note that technically the order of the parameters is significant in an HTTP URI anyway, i.e. a conforming comparison of two URLs where the parameters (in the path or in the query string) were in a different order would have to assume that they could reference a different resource.

这篇关于URL路径参数使用案例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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