J'ai fait la même chose en PHP. Comment utiliser jquery-cookie Perl: Comment utiliser les cookies PHP: Comment utiliser les cookies Python3: Comment utiliser les cookies
Envoyez un cookie
cookie_put.rb
#! /usr/bin/ruby
#
# cookie_put.rb
#
#
puts "Set-Cookie: message='Good Morning';\n"
puts "Set-Cookie: aa='Bonjour.';\n"
puts "Set-Cookie: bb='C'est ensoleillé aujourd'hui.';\n"
puts "Set-Cookie: cc='Bonjour';\n"
puts 'Content-Type: text/html',"\n"
puts "\n"
puts "<!DOCTYPE html>"
puts "<html lang=\"ja\">"
puts "<head>"
puts "<title>cookie put</title>"
puts "</head>"
puts "<body>"
puts "cookie_put.rb<p />"
puts "Aug/15/2020<p/>"
puts "</body>"
puts "</html>"
Vérifier les cookies
cookie_get.rb
#! /usr/bin/ruby
#
# cookie_get.rb
#
cookie = Hash.new
ENV['HTTP_COOKIE'].split(/;\s/).each do |bo|
mo = bo.split(/=/)
cookie[mo[0]] = mo[1]
end
puts "Content-type: text/html\n\n"
puts "<!DOCTYPE html>"
puts "<html lang=\"ja\">"
puts "<head>"
puts "<meta http-equiv=\"CONTENT-TYPE\" content=\"text/html; charset=utf-8\" />"
puts "<title>Cookie Test</title></head>"
puts "<body>"
puts "Cookie Test<p />"
# puts cookie
cookie.each {|key, value|
puts key,":",value,"<p />"
}
puts "</body></html>"
Recommended Posts