Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:48:22+00:00 2026-05-24T02:48:22+00:00

I have two rails applications App1 and App2 both running on separate URLs but

  • 0

I have two rails applications App1 and App2 both running on separate URLs but on same machine. App1 fetch some data using Net::HTTP from App2. What I need to do is to set a cookie in App2 when request is made from App1. Currently, it’s not setting the cookie. Do I need to add some header in App1 while sending request to App2, or what?

Here is the code to fetch the content:

def get_content(url)

    uri = URI.parse(url)

    params = Hash[*uri.query.split("&").map {|part| part.split("=") }.flatten]

    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Get.new(uri.path)
    request.set_form_data( params )
    request = Net::HTTP::Get.new( uri.path+ '?' + request.body )

    if uri.scheme == "https"  # enable SSL/TLS
      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
    http.start do
      http.request(request) do|res|
        return res.body
      end
    end
end

Please advice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:48:23+00:00Added an answer on May 24, 2026 at 2:48 am

    first question: Where do you want to place the cookie? On the client who is browsing your website?

    Is your request flow like:

    Client –[web browser]–> App 1 –[net::http]–> App2

    If this is the flow, you have to proxy the cookie:

    def get_content(url)
    
        uri = URI.parse(url)
    
        params = Hash[*uri.query.split("&").map {|part| part.split("=") }.flatten]
    
        http = Net::HTTP.new(uri.host, uri.port)
        request = Net::HTTP::Get.new(uri.path)
        request.set_form_data( params )
        request = Net::HTTP::Get.new( uri.path+ '?' + request.body )
    
        if uri.scheme == "https"  # enable SSL/TLS
          http.use_ssl = true
          http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        end
        http.start do
          http.request(request) do |res|
            # yummy, parse some cookies here
            app2_cookies  = CGI::Cookie.parse(res['Set-Cookie']);
    
            app2_cookies.each do |c_name, c_cookie|
              # this is the cookies object from rails! Make sure this is accessible here!
              # the cookie will now be set on the client side
              cookies[c_name] = c_cookie.value
            end
    
            return res.body
          end
        end
    end
    

    Make sure you require CGI::Cookie

    Here are the docs:

    http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTPHeader.html#M001307

    http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/CGI/Cookie.html#M000170

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Rails 3 applications that will share portions of the same database
I have two forms in my rails app. They both exist in separate tabs
I have two virtual hosts on my server pointing towards two separate rails applications.
I'm working on a Rails application where I have some a set of two
I have installed two different version of rails in same gem set. When I
I have two rails application running at different ports. First at 3000 and the
In rails application I have two models: Food and Drink . Both food and
I have two rails applications. I would like to submit data from one application
I have two rails applications, hosted on heroku, that need to communicate. For now,
I have a rails application running over Postgres. I have two servers: one for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.