I intend to make a call from a Ruby on Rails application:
c = Curl::Easy.http_post("https://example.com", json_string_goes_here) do |curl|
curl.headers['Accept'] = 'application/json'
curl.headers['Content-Type'] = 'application/json'
curl.headers['Api-Version'] = '2.2'
end
The response should have custom headers:
X-Custom1 : "some value"
X-Custom2 : "another value"
How do I iterate over the response headers to compare the values to what I was expecting?
Using Curl::Easy's
header_str
you can access the returned headers as a string. From the documentation:To test this I turned on the built-in Gem server using:
Here's some code to test this:
Capturing the response, and breaking the remaining string into a hash making it easier to use, is simple:
Testing again, in Pry: