如何在Ruby中使用机械化执行Head请求 [英] How can I perform a Head request using mechanize in Ruby

查看:76
本文介绍了如何在Ruby中使用机械化执行Head请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Faraday(Faraday.head网址)执行HEAD请求,但是我正在当前项目中使用Mechanize.

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

我想从标题(文件名)中获取一个值而不下载文件.机械化宝石是否提供了这样的选择?我正在使用v2.0.

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.

推荐答案

就像get一样,但它是head:

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"]

这篇关于如何在Ruby中使用机械化执行Head请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆