ruby net http with cookies

stackoverflow上的解答,可以参考,但与我实际情况不符合

http://stackoverflow.com/questions/1486703/how-to-implement-cookie-support-in-ruby-net-http

#here is my version: get previous page with cookies
#get previous url or whatever url you need
uri = URI(request.headers["HTTP_REFERER"]) 
http = Net::HTTP.new(uri.host)
cookie_string=""
all_cookies = request.cookies
all_cookies.each { | key, value |
                   cookie_string+="; " if cookie_string!=""
                   cookie_string+=(key+"="+value)
                 }
response = http.get(uri.path,{'Cookie' => cookie_string})

猜你喜欢

转载自xiao-hui.iteye.com/blog/2275285