How can I perform a Head request using mechanize in Ruby

别来无恙 提交于 2019-12-10 15:28:09

问题


I can perform a HEAD request with Faraday (Faraday.head url), but I am using Mechanize on my current project.

I would like to grab a value from the header (filename) without downloading the file. Does the Mechanize gem provide such an option? I am using v2.0.


回答1:


Just like get but it's head instead:

page = agent.head 'http://www.google.com/'
page.body.length
#=> 0
page.header.keys
#=> ["date", "expires", "cache-control", "content-type", "set-cookie", "p3p", "server", "x-xss-protection", "x-frame-options", "transfer-encoding"]


来源:https://stackoverflow.com/questions/13872530/how-can-i-perform-a-head-request-using-mechanize-in-ruby

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