使用ruby,从需要身份验证的IP摄像头抓取单个JPG图像并将图像写入文件的最简单方法是什么?例如,使用URL的IP摄像头:
http://192.168.69.81/cgi/jpg/image.cgi
我不需要对图像进行任何操作。
提前致谢。
答案 0 :(得分:2)
打开远程位置并将文件写为名为image.jpg的jpeg图像:
require 'open-uri'
url = 'http://192.168.69.81/cgi/jpg/image.cgi'
open(url, :http_basic_authentication => ['username', 'password']) do |f|
open('image.jpg','wb') do |file|
file.puts f.read
end
end
答案 1 :(得分:0)
你可以试试这个
require 'net/http'
Net::HTTP.start(url, port) do |http|
req = Net::HTTP::Get.new('/image.cgi')
req.basic_auth 'username', 'password'
response = http.request(req)
open("image.cgi", "wb") do |file|
file.write(response.body)
end
end