BlackHatSamurai BlackHatSamurai - 1 year ago 158
Ruby Question

Get response headers from Ruby HTTP request

I'm making an HTTP request with Ruby using Net::HTTP, and I can't figure out how to get all the response headers.

I tried

and nothing is working.

Answer Source

The response object actually contains the headers.

See "Net::HTTPResponse" for more infomation.

You can do:


You can also call each_header or each on the response object to iterate through the headers.

If you really want the headers outside of the response object, call response.to_hash

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download