iPhone在NSURL中发送UTF-8参数
我正在尝试用从右到左的语言(希伯来语阿拉伯语等)在谷歌中搜索,我已经尝试过,
NSURL *url = [NSURL URLWithString:@"http://www.google.com/search?q=امريكا"];
[[UIApplication sharedApplication] openURL:url];
但根本没有用,它会忽略网址并跳过该方法,就好像它是空的一样..而如果我输入英文字符工作得很好..对于那些 utf-8 字符还有另一种方法吗?
i'm trying to search in google in a right to left language (hebrew arabic etc..) and i've tried this
NSURL *url = [NSURL URLWithString:@"http://www.google.com/search?q=امريكا"];
[[UIApplication sharedApplication] openURL:url];
but no use at all it ignore the url and skip the method as if it's empty .. while if i put english characters it's work just fine .. is there another way for those utf-8 character ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
警告:我不进行 iPhone 编程,并且不知道您正在使用的操作/方法应该如何工作。
但是,URL 似乎没有被转义。
URL RFC 对 URL 中的字符编码明确含糊不清(“本规范不强制要求任何特定的字符编码”)。但是,URL 仅限于 ASCII 字母、数字和一小组特殊字符。其他所有内容都必须使用 百分比编码 进行编码。
尽管 URL 语法未指定字符集编码,但行为良好的服务器应该接受 UTF-8 字符,只要它们是百分比转义的。因此,希伯来字符 Sheva(unicode 05B0)应以
%D6%B0</code> 形式存储在 URL 中。
要进行诊断,您需要查看通过网络传输的实际字节。不确定这对于 iPhone 来说有多容易,但是诸如 Fiddler 之类的日志代理可能会帮助(是的,我知道,这是一个 Windows 应用程序,但我确信 Mac 上有一个等效的应用程序)。
Caveat: I don't do iPhone programming, and don't know how the operations/methods that you're using are supposed to work.
However, it seems like the URL is not being escaped.
The URL RFC is explicitly vague on character encoding within a URL ("This specification does not mandate any particular character encoding"). However, the URL is limited to ASCII letters, digits, and a small set of special characters. Everything else has to be encoded using percent-encoding.
Although the URL syntax doesn't specify a character-set encoding, a well-behaved server should accept UTF-8 characters, as long as they're percent-escaped. So the Hebrew character Sheva, unicode 05B0, should be stored in a URL as
%D6%B0
.To diagnose, you'll need to look at the actual bytes going over the wire. Not sure how easy this will be to do with the iPhone, but a logging proxy such as Fiddler may help (yes, I know, it's a Windows app, but I'm sure there's an equivalent for the Mac).