Ruby 卷曲比。 httparty 订阅推送 API 流媒体
Ruby curl Vs. httparty subscribe to a push API streaming
我正在尝试订阅一个 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
、其他 gems 或 ruby 是否有关于如何做到这一点的建议?
我用 typhoeus
gem
做到了
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
我正在尝试订阅一个 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
、其他 gems 或 ruby 是否有关于如何做到这一点的建议?
我用 typhoeus
gem
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