1

I was recently making use of this: Send cookies with curl

I'm now trying to automate the process in a ruby script.

However, I don't see anything native that will load cookies from a file for a given request.

What is the best way to load cookies from a file for net/http requests in Ruby?

Update: I'm just using a browser plugin to dump all my cookies into a file. I'd like to load that file for use as cookies. the curl example would be: curl -b cookies.txt http://example.com (notice I'm only using '-b').

I'd really like to avoid looping through everything in the file and parsing out the cookies and setting headers individually. I'm looking for the ruby equivalent of this python code (ref: Using cookies.txt file with Python Requests)

import requests, cookielib

cj = cookielib.MozillaCookieJar('cookies.txt')
cj.load()
r = requests.get(url, cookies=cj)
Ramy
  • 20,541
  • 41
  • 103
  • 153

0 Answers0