Created
June 24, 2016 14:14
-
-
Save amitpatelx/74d31f5ba67f6c31169050123558b27a to your computer and use it in GitHub Desktop.
How to download images from different rails application sharing a session?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code is assumed to be part of one application(http://microservices2.btdashboard.com) sharing session with other(http://microservices1.btdashboard.com) | |
# '_your_app_session' is session_store key config in session_store.rb | |
# 'KzBxYy9jUURwbEYxR3ZCRmI3' is value of session cookie read in controller action | |
cookie = Mechanize::Cookie.new('_your_app_session', 'KzBxYy9jUURwbEYxR3ZCRmI3') | |
cookie.domain = ".btdashboard.com" # check domain config in session_store.rb | |
cookie.path='/' # Set as per your application settings | |
# More cookie settins as required | |
uri = URI.parse('http://microservices1.btdashboard.com') | |
agent = Mechanize.new | |
agent.cookie_jar.add(uri, cookie) | |
# Read it. You won't get 401 | |
image = agent.get('http://microservices1.btdashboard.com/media/1/sample.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment