使用curl,我可以执行HTTP头请求,如下所示:
curl -I 'http://www.google.com'如何使用Curb执行此过程?我不想找回身体,因为这会花费太多时间。
发布于 2013-05-05 21:38:04
-I/--head选项执行HEAD请求。对于libcurl C API,您需要设置CURLOPT_NOBODY选项。
使用路缘,可以在控制柄上设置此选项,如下所示:
h = Curl::Easy.new("http://www.google.com")
h.set :nobody, true
h.perform
puts h.header_str
# HTTP/1.1 302 Found
# Location: http://www.google.fr/
# Cache-Control: private
# Content-Type: text/html; charset=UTF-8
# ...作为另一种选择,您可以使用方便的快捷方式之一,例如:
h = Curl::Easy.new("http://www.google.com")
# This sets the option behind the scenes, and call `perform`
h.http_head
puts h.header_str
# ...或者像这样,使用class方法:
h = Curl::Easy.http_head("http://www.google.com")
puts h.header_str
# ...注意:最终的快捷方式是Curl.head("http://www.google.com")__。这就是说,在使用它之前,请等到下一个抑制版本,因为在撰写本文时,它是而不是,并且刚刚被修补:请参阅此。
https://stackoverflow.com/questions/16384237
复制相似问题