5

I intend to send a request like the following:

c = Curl::Easy.http_post("https://example.com", json_string   
    ) do |curl|
      curl.headers['Accept'] = 'application/json'
      curl.headers['Content-Type'] = 'application/json'
      curl.headers['Api-Version'] = '2.2'
    end

I want to log the exact http request that is being made. Is there a way to get the actual request that was made (base path, query parameters, headers and body)?

DigitalRoss
  • 143,651
  • 25
  • 248
  • 329
Mike Malloy
  • 1,520
  • 1
  • 15
  • 19

2 Answers2

1

The on_debug handler has helped me before. In your example you could try:

curl.on_debug do |type, data|
  puts type, data
end
Colin Curtin
  • 2,093
  • 15
  • 17
0

You can reach the solution in differents manner:

Inside your block you can put:

curl.verbose = true   # that prints a detailed output of the connection

Or outside the block:

c.url  # return the url with queries
c.total_time # retrieve the total time for the prev transfer (name resolving, TCP,...)
c.header_str # return the response header
c.headers # return your call header
c.body_str # return the body of the response

Remember to call c.perform (if not yet performed) before call these methods.

Many more option can be found here: http://curb.rubyforge.org/classes/Curl/Easy.html#M000001

damoiser
  • 6,058
  • 3
  • 40
  • 66