NSURL的parameterString混淆使用';' vs'&' [英] NSURL's parameterString confusion with use of ';' vs '&'

查看:384
本文介绍了NSURL的parameterString混淆使用';' vs'&'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 - [NSURL parameterString] 来解析我已经通过的网址的参数。它表示网址必须符合 RFC 1808 ,但现在想知道我们是否会这样做?我们使用类似:

I'd like to use -[NSURL parameterString] to parse out the parameters of a URL I've been passed. It says URL must conform to RFC 1808 but now wondering if ours do?!? We use something like:

http:// server / path / query?property1 = value1& property2 = value2

但RFC 1808从不提及&符号(& )作为有效的参数分隔符(至少是我读它的方式)。它建议使用分号(; )。也许是因为它是在1995年起草的?是否& 已替换; ?如果这样任何人验证NSURL的parameterString也将解析与&作为分隔符?

but RFC 1808 never mentions the ampersand (&) as a valid parameter separator (at least the way I read it). It suggests the semicolon (;). Perhaps because it was drafted in 1995? Has the & replaced the ;? If so anyone verify if NSURL's parameterString will also parse with & as delimiter?

在我们挖大洞之前,正确是什么?

What's the "right" way before we dig a big a hole?

推荐答案

根据RFC 1808(2.1。URL语法组件),正确的语法如下:

According to RFC 1808 (2.1. URL Syntactic Components) correct syntax is as follows :

<scheme>://<net_loc>/<path>;<params>?<query>#<fragment>

它说明查询信息的格式是根据RFC 1738的3.3节告诉我们:

It says query information is formatted as per Section 3.3 of RFC 1738 which tells us :

在路径和searchpart组件中,保留/,;,?。

"Within the path and searchpart components, "/", ";", "?" are reserved."

我上面说的在你的URL路径(到你的CGI)是:

To me the above says that in your URL the path (to your CGI) is :

http://server/path/query

,查询为:

property1=value1&property2=value2 

字符。所以你没事。其实使用&作为此查询字符串中的分隔符来自 CGI规范,而不是URL RFC:

Which does not contain any reserved characters. So you are OK. In fact the use of the "&" as a separator in the query string here derives from the CGI specification and not the URL RFC :

表单数据是由&字符分隔的名称=值对的流。

"Form data is a stream of name=value pairs separated by the & character."

这篇关于NSURL的parameterString混淆使用';' vs'&amp;'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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