ruby - 如何打印有关 NET :HTTPRequest for debug purposes? 的信息

标签 ruby http https

我是从 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

http://github.com/augustl/net-http-cheat-sheet 中还有更多内容:)

关于ruby - 如何打印有关 NET :HTTPRequest for debug purposes? 的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2128698/

相关文章:

ruby - "k.send :hello"- 如果 k 是 "receiver",谁是发件人?

Ruby - 数组方法混淆

http - netstat 上的奇怪连接

https - 从 HTTPS 重定向到 HTTP 的安全问题?

iOS 错误代码=-1003 “A server with the specified hostname could not be found.”

ruby-on-rails - Cucumber 是否不需要编写单元测试?

ruby-on-rails - 'sudo gem install' 或 'gem install' 和 gem 位置

java 11 HttpClient 导致无休止的 SSL 循环

java - 如何使用 Jsoup 跟踪来自 404 的重定向

node.js - 运行在任意端口上的应用程序如何从互联网上获取数据包?