简体   繁体   English

使用HTTParty捕获特定请求

[英]Capture specific request with HTTParty

I would like to capture the full request (raw_request -- what went over the wire) for a given action without using a proxy. 我想在不使用代理的情况下捕获给定操作的完整请求(raw_request-通过网络传输的内容)。

I am aware of the debug_output method on the Class, and that might be part of the solution. 我知道Class上的debug_output方法,这可能是解决方案的一部分。 But unclear on how to set it on a per request basis. 但尚不清楚如何根据每个请求进行设置。

Consider the following ... 考虑以下 ...

@response = HTTParty.post(@job.callback_url, body: @job.to_json)
notification = Notification.new
notification.response_body = @response.body
notification.response_code = @response.code
notification.request_body = ????

Thanks! 谢谢!

Jonathan 乔纳森

      HTTParty.post(url, :body => body, :debug_output => $stdout)

@response.request将包含请求对象。

Add the following under your include HTTParty line: include HTTParty行下添加以下内容:

debug_output $stdout

This sets an output stream for debugging and the output stream is passed on to Net::HTTP#set_debug_output. 这将设置用于调试的输出流,并将该输出流传递到Net :: HTTP#set_debug_output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM