13

I would like to capture the full request (raw_request -- what went over the wire) for a given action without using a proxy.

I am aware of the debug_output method on the Class, and that might be part of the solution. 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

Jonathan
  • 16,077
  • 12
  • 67
  • 106

3 Answers3

19

@response.request will contain the request object.

Sohan
  • 3,757
  • 2
  • 24
  • 24
  • how do I get the raw_request? – Jonathan Aug 02 '11 at 19:11
  • 1
    @Jonathan I would not recommend this except to debug your code, but to answer your question and get at the raw request, you can use ruby's `instance_variable_get` method: `@response.request.instance_variable_get(:@raw_request)` – philtr Sep 22 '13 at 21:01
18
      HTTParty.post(url, :body => body, :debug_output => $stdout)
Brian Low
  • 11,605
  • 4
  • 58
  • 63
9

Add the following under your include HTTParty line:

debug_output $stdout

This sets an output stream for debugging and the output stream is passed on to Net::HTTP#set_debug_output.

Simpleton
  • 6,285
  • 11
  • 53
  • 87
  • 4
    "I am aware of the debug_output method on the Class, and that might be part of the solution. But unclear on how to set it on a per request basis." – Jonathan Sep 06 '11 at 14:09
  • 5
    I've added this, but how do I view the output? I'm not seeing it in my logs. – doremi Aug 07 '12 at 19:27