Posting JSON with http_request


#1

Hello,

It looks like posting JSON with http_request broke in Chef 11.8. (See:
https://tickets.opscode.com/browse/CHEF-4877) Does anyone know of a
workaround?

Thanks,

-Nathan


#2

On Friday, March 14, 2014 at 7:25 AM, Nathan Mische wrote:

Hello,

It looks like posting JSON with http_request broke in Chef 11.8. (See: https://tickets.opscode.com/browse/CHEF-4877) Does anyone know of a workaround?

Thanks,

-Nathan
Convert the body to a JSON string with {“thing” => “value”}.to_json, and add the correct content-type header.


Daniel DeLeo


#3

Thanks Daniel. Converting the documentation sample to the following works:

http_request “posting data” do
action :post
url "http://example.com/check_in"
message ({:some => “data”}.to_json)
headers({“AUTHORIZATION” => “Basic
#{Base64.encode64(“username:password”)}”,“Content-Type” =>
“application/data”})
end

Do you know, has the behavior of http_request changed and the documentation
(http://docs.opscode.com/resource_http_request.html#examples) not been
updated? Or is this a regression?

Thanks Again,

-Nathan

On Wed, Mar 19, 2014 at 11:44 AM, Daniel DeLeo dan@kallistec.com wrote:

On Friday, March 14, 2014 at 7:25 AM, Nathan Mische wrote:

Hello,

It looks like posting JSON with http_request broke in Chef 11.8. (See:
https://tickets.opscode.com/browse/CHEF-4877) Does anyone know of a
workaround?

Thanks,

-Nathan
Convert the body to a JSON string with {“thing” => “value”}.to_json, and
add the correct content-type header.


Daniel DeLeo