2

使用 ruby​​,从需要身份验证的 IP 摄像机中获取单个 JPG 图像并将图像写入文件的最简单方法是什么?例如,使用 URL 的 IP 摄像机:

http://192.168.69.81/cgi/jpg/image.cgi

我不需要对图像进行任何操作。

提前致谢。

4

2 回答 2

2

Open the remote location and write the file as a jpeg image called image.jpg:

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
于 2012-11-03T12:35:09.063 回答
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
于 2012-11-03T12:46:15.343 回答