Capturing http response


#1

I’m trying to send a post request to an HTTP server and capture some parts of
the json response in a chef resourse to use in a follow up HTTP request. I’ve
found http://docs.opscode.com/resource_http_request.html which seems great to
do the first post, but I’m having trouble finding documentation/explanation
about capturing the response body for the request. Anyone have any pointers?

Thanks,
-ryan


#2

Resources don’t have return values like this, so you would want to use a ruby_block (or LWRP) along with Net::HTTP or a similar HTTP client library. You can use Chef::HTTP as a convenient wrapper client that already has stuff like HTTPS verification set up (if configured in client.rb, which it should be):

Chef::HTTP(‘https://hostname’).get(’/path’).to_s

–Noah

On Jun 16, 2014, at 9:44 AM, gowlin@gmail.com wrote:

I’m trying to send a post request to an HTTP server and capture some parts of
the json response in a chef resourse to use in a follow up HTTP request. I’ve
found http://docs.opscode.com/resource_http_request.html which seems great to
do the first post, but I’m having trouble finding documentation/explanation
about capturing the response body for the request. Anyone have any pointers?

Thanks,
-ryan