如何通过机械化帖子请求查看传递的标题?
换句话说,如果我使用的是.post网址,我希望看到在帖子请求中发送的请求标头。
答案 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"=>["*/*"], ... }