带有变量的URI [英] URI with variable
本文介绍了带有变量的URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在单独的行上包含uid的文件,并且我试图将它们包括在URI中.
I've got a file with uids on separate lines, and I'm trying to include them in a URI.
File.open("File Path").readlines.each do |line|
puts line
uid = line
uri = URI("http://example:port/path/variable=#{uid}&fragment")
res = Net::HTTP.get_response(uri)
puts res.body
但是我收到一条错误消息:错误的URI(不是URI?)."
But I get an error saying "bad URI(is not URI?)".
有人可以帮忙吗?
谢谢
推荐答案
可以尝试
uid = line.strip
strip
删除前导和尾随空格和换行符.
The strip
removes leading and trailing spaces and newlines.
使用
p uid
或
puts uid.inspect
您可能会看到字符串的真实内容.
you may see the real content of the string.
这篇关于带有变量的URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文