我是从 Java 转过来接触 Ruby 的新手。我正在尝试发出一个 http get 请求,我得到一个 400 的 http 响应代码。我通过 http 调用的服务非常特殊,我很确定我的请求不完全正确。 “深入了解”req
会很有帮助在我执行 head 请求(如下)以仔细检查正在发送的 request_headers 是否是我认为我正在发送的内容之后。有没有办法打印出 req 对象?
req = Net::HTTP.new(url.host, url.port)
req.use_ssl = true
res = req.head(pathWithScope, request_headers)
code = res.code.to_i
puts "Response code: #{code}"
我试过这个:puts "Request Debug: #{req.inspect}"
但它只打印这个:#<Net::HTTP www.blah.com:443 open=false>
最佳答案
使用set_debug_output
。
http = Net::HTTP.new(url.host, url.port)
http.set_debug_output($stdout) # Logger.new("foo.log") works too
关于ruby - 如何打印有关 NET :HTTPRequest for debug purposes? 的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2128698/