iphone - 带有编码的 NSURL
<p><p>我有一个这个 URL,但我似乎无法让下面的代码工作</p>
<p>在此代码中 urlToGrab = <a href="http://192.1.1.233:8000/en-US/app/search/flashtimeline?auto_pause=true&q=search%20host%3D%22JRVIN-LT%22" rel="noreferrer noopener nofollow">http://192.1.1.233:8000/en-US/app/search/flashtimeline?auto_pause=true&q=search%20host%3D%22JRVIN-LT%22</a> </p>
<pre><code>NSURL *url = ;
];
</code></pre>
<p>此代码不起作用。设置断点时'url'为空。如果我使用“http://192.1.1.233:8000/en-US/app/search/flashtimeline?auto_pause=true&q=search”,它将起作用。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您必须先对字符串进行 URL 解码。示例:</p>
<pre><code>NSString * urlToGrab = [[@"http://192.1.1.233:8000/en-US/app/search/flashtimeline?auto_pause=true&q=search%20host%3D%22JRVIN-LT%22"
stringByReplacingOccurrencesOfString:@"+" withString:@" "]
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = ;
];
</code></pre>
<p>将“+”替换为“”以防万一您有另一个包含“+”的编码 URL。</p></p>
<p style="font-size: 20px;">关于iphone - 带有编码的 NSURL,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/8131144/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/8131144/
</a>
</p>
页:
[1]