有一个我要订阅的API端点。当我做
curl -vL 'url'
我每5秒钟接收一次数据流,并且连接保持打开状态。
当我尝试从httparty
做同样的事情
response = HTTParty.get('url', follow_redirects: true)
只是停止并且不执行任何操作
当我这样做
response = HTTParty.head('url', follow_redirects: true)
我知道
ERR_596_SERVICE_NOT_FOUND
对于httparty
,其他宝石或红宝石的一般用途,是否有任何建议?
答案 0 :(得分:0)
我能够用typhoeus
宝石来做到这一点
request = Typhoeus::Request.new("url", followlocation: true)
request.on_headers do |response|
if response.code != 200
raise "Request failed"
end
end
request.on_body do |chunk|
puts "****************"
puts chunk.inspect
puts "****************"
end
request.on_complete do |response|
# downloaded_file.close
# Note that response.body is ""
puts "connection got closed maged"
end
request.run