@cqcn1991 你好,我也遇到了同样的问题,请问你是如何解决的呢?谢谢! 我的代码:
require 'open-uri'
def index
if params[:search].present?
url = "http://api.map.baidu.com/geocoder/v2/?address=#{params[:search]}&output=json&ak=AA50c6765a5a346c22348295adca7877"
content = open(url).read
提示错误: bad URI(is not URI?): http://api.map.baidu.com/geocoder/v2/?address=&output=json&ak=AA50c6765a5a346c22348295adca7877百度大厦
后来找到答案了,需要转码:
url_escape = URI::escape(url)
content = open(url_escape).read