机械师邮政标题

时间:2014-04-20 15:17:48

标签: ruby mechanize

如何通过机械化帖子请求查看传递的标题?

换句话说,如果我使用的是.post网址,我希望看到在帖子请求中发送的请求标头。

1 个答案:

答案 0 :(得分:0)

您可以附加pre_connect_hook并检查请求标题。

require 'mechanize'

agent = Mechanize.new do |a|
  a.pre_connect_hooks << lambda do |a, request|
    p request.to_hash # convert the request to header hash and dump it
  end
end

agent.post 'http://stackoverflow.com'

# {"accept-encoding"=>["gzip,deflate,identity"], "accept"=>["*/*"], ... }
相关问题