views:

33

answers:

1

That's my code.

Now I need to SEND a cookie to the host but I can't find a solution.


def get_network_file(url=nil)

  begin
    http = Net::HTTP.new( @service_server, 80 )
    resp, data = http.get( url, { "Accept-Language" => @locale } )
    if resp.code.to_i != 200
      RAILS_DEFAULT_LOGGER.error "*** return code != 200. code = #{resp.code}"
      return ""
    end
  rescue Exception => exc
    RAILS_DEFAULT_LOGGER.error "*** message --> #{exc.message}"
    return ""
  end
  return data
end

end

A: 

You pass cookies via the same hash you're sending the "Accept-Language" header, something like:

resp, data = http.get( url, { "Accept-Language" => @locale, "Cookie" => "YOUR_COOKIE" } )

Odds are you'll need to capture the cookie first, though. See this for examples of cookie handling.

jcrossley3
Thanks. I'll try.
Juanin