Display HTTP headers using Open::URI?

懵懂的女人 提交于 2019-12-05 03:52:28
Unixmonkey

Use the meta method of the virtual filehandle:

open('http://google.com'){|f| pp f.meta  }
{"x-frame-options"=>"SAMEORIGIN",
 "expires"=>"-1",
 "p3p"=>
  "CP=\"This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info.\"",
 "content-type"=>"text/html; charset=ISO-8859-1",
 "date"=>"Mon, 17 Dec 2012 14:37:29 GMT",
 "server"=>"gws",
 "x-xss-protection"=>"1; mode=block",
 "set-cookie"=>
  "PREF=ID=d2fb8a93d369bcd2:FF=0:TM=1355755049:LM=1355755049:S=ONVSP6n2jtluFgll; expires=Wed, 17-Dec-2014 14:37:29 GMT; path=/; domain=.google.com, NID=67=OFEvvHCOa3C6wScQCUIKfu_89oL9MSmnFjwN-u5LX_foP8NLsX7G9dq48NLVrf4WUXhqOA1jb38s0e9qeRp1Iwx_LT_N8IuF0Qi6dXVtR2zdvA86INqtfg5uNrKvxJfJ; expires=Tue, 18-Jun-2013 14:37:29 GMT; path=/; domain=.google.com; HttpOnly",
 "cache-control"=>"private, max-age=0",
 "transfer-encoding"=>"chunked"}

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/OpenURI/Meta.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!