ios - NSURLComponents 获取百分比编码
<p><p>根据<code>NSURLComponents</code>的文档:</p>
<blockquote>
<p>If you set the unencoded property, you can then obtain the encoded
equivalent by reading the encoded property value and vice versa.</p>
</blockquote>
<p>我试图获取查询的百分比编码版本和 url 的路径,但我错过了一些东西:</p>
<pre><code>NSURL * url = ;
NSURLComponents * components = [ initWithURL:url resolvingAgainstBaseURL:YES];
components.query = @"oauth_callback=http://google.com";
NSLog(@"Encoded: %@", );
//-> Encoded: http://google.com?oauth_callback=http://google.com
//Does not encode "/" or ":"
</code></pre>
<p>我在哪里失败了?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为<code>NSURLComponent</code> 的行为是对的。
来自 <a href="http://en.wikipedia.org/wiki/Percent-encoding#Types_of_URI_characters" rel="noreferrer noopener nofollow">Wikipedia</a> :</p>
<blockquote>
<p>In the "query" component of a URI (the part after a ? character), for
example, "/" is still considered a reserved character but it normally
has no reserved purpose, unless a particular URI scheme says
otherwise. The character does not need to be percent-encoded when it
has no reserved purpose.</p>
</blockquote></p>
<p style="font-size: 20px;">关于ios - NSURLComponents 获取百分比编码,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25259961/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25259961/
</a>
</p>
页:
[1]