Home Ruby Read Remote Uri
Post
Cancel

Ruby Read Remote Uri

注意: 该文件名称不要带有中文,否则需要escape

+    def read_remote_file url
+      require 'open-uri'
+      return URI.open(url).read
+    end

如果想转义的话,建议只对file-name做转义.不要对 http:// 转义,否则无法被URI.open 读取

参考:https://stackoverflow.com/questions/68635238/undefined-method-encode-for-urimodule-with-gem-rspotify

另外, ruby2, ruby3 的用法不同. 

ruby2:  URI.encode    URI.escape   , 

ruby3:  CGI.escape   (需要 require 'cgi') 

This post is licensed under CC BY 4.0 by the author.