我試圖打開一個名爲test.txt的文件,然後將每行導入一個名爲'line'的變量,然後將其添加到url文件中以發出請求。Ruby:Net :: HTTP解析在結尾添加%0A
require 'net/http'
require 'uri'
puts "Enter URL :-"
gurl = gets.chomp
total = File.foreach('test.txt').count
c=0
while(c < total)
line = IO.readlines("test.txt")[c]
aurl = "#{gurl}/#{line}"
encoded_url = URI.encode(aurl)
url = URI.parse(encoded_url)
puts "\n #{url} \n"
res = Net::HTTP.get_response(url)
puts "\n Response received for #{line} => #{res.code} \n"
c+=1
end
樣品outpute =>
http://www.example.com/z.php%0A
Response received for z.php
=> 404
http://www.example.com/index.php%0A
Response received for index.php
=> 404
反正逸出%0A(換行)? 所有新紅寶石
我已經解決了這個問題,但是這個工作也很完美。 :) –
好。但請不要讀取n + 1次的文件;) –