【发布时间】:2013-11-28 07:35:12
【问题描述】:
我目前正在编写一个代码,我正在请求一个 URL,请求路径上有空格:
http://example.com/path1/path2/some details.detail?keyword=key word
我正在使用rest-client gem。
url = http://example.com/path1/path2/some details.detail?keyword=key word
RestClient::Request.execute(method: :get, url: url)
但是它会抛出一个错误:
URI::InvalidURIError: bad URI(is not URI?): http://example.com/path1/path2/some details.detail?keyword=key word
文档建议先解析和规范化 URL:
parsed_url = Addressable::URI.parse(url).normalize.to_str
# parsed_url is now: http://example.com/path1/path2/some%20details.detail?keyword=key%20word
RestClient::Request.execute(method: :get, url: parsed_url)
但错误依然存在。
URI::InvalidURIError: bad URI(is not URI?): http://example.com/path1/path2/some details.detail?keyword=key%20word
它似乎无法解析 url 的 /some details.detail 部分。
有人遇到过同样的问题吗?
【问题讨论】:
标签: ruby parsing rest rest-client