Use an http cookie that implements RFS-compliant parsing and rendering, plus a jar.
A rough example that happens after a redirect after login:
require 'uri' require 'net/http' require 'http-cookie' uri = URI('...') jar = HTTP::CookieJar.new Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| req = Net::HTTP::Post.new uri req.form_data = { ... } res = http.request req res.get_fields('Set-Cookie').each do |value| jar.parse(value, req.uri) end fail unless res.code == '302' req = Net::HTTP::Get.new(uri + res['Location']) req['Cookie'] = HTTP::Cookie.cookie_value(jar.cookies(uri)) res = http.request req end
What for? Since the answers above are incredibly inadequate and flat, they don’t work in many scenarios related to RFC (this happened to me), so relying on lib itself using just what you need is infinitely more reliable if you want to process more one specific case.
Lloeki Sep 30 '15 at 14:21 2015-09-30 14:21
source share