Persist session/cookies across successive get requests -
i running script needs execute several requests api using restclient gem.
however, api needs cookies & session persisted in order function properly.
i have this:
# first request url = "http://example-api.com/first-endpoint?param1=foo¶m2=bar request = restclient.get url, :content_type => :json, :accept => :json cookies = request.cookies # second request url = "http://example-api.com/second-endpoint?param1=foo¶m2=bar request = restclient.get url, :content_type => :json, :accept => :json
in order make second request work, need keep same session , cookies. using restclient, can send cookies in post request this:
restclient.post post_url, {}, {:cookies => cookies}
but couldn't find in documentation & on stackoverflow way request.
how should proceed "keep" cookies alive between 2 successive requests ? i'm open using gem or technique if restclient doesn't support this.
any appreciated !
note if want more fledged cookie support, in recent versions of rest-client (>= 2.0.0) can use actual cookie jar (http::cookiejar
), behaves more browser in following expiration / domain / path restrictions.
resp = restclient.get(url) jar = resp.cookie_jar resp2 = restclient::request.execute(url: someurl, method: :get, cookies: jar)
Comments
Post a Comment