我試圖解析具有一些特殊的字符,如在用戶名@
和密碼的FTP網址:當我嘗試如何解析具有特殊字符的用戶名或密碼的FTP URL?
username:[email protected]@ftp.myhost.com/mypath
:
URI.parse(url)
我得到:
URI::InvalidURIError: the scheme ftp does not accept registry part: username:[email protected]@ftp.myhost.com (or bad hostname?)
然後,我試着編碼url:
url = URI.encode(url, '@')
而且還得到了另一個錯誤:
URI::InvalidURIError: the scheme ftp does not accept registry part: username:p%40sswrd%40ftp.myhost.com (or bad hostname?)
最後,我嘗試另一種解決方案:
URI::FTP.build(:userinfo => 'username:[email protected]', :host=>'ftp.myhost.com', :path => '/mypath')
但我也得到了一個錯誤:
URI::InvalidComponentError: bad component(expected user component): [email protected]
我使用的紅寶石1.8 0.7。
除了你沒有回答你自己的問題,如何解析... – 2014-12-16 18:57:14