在厨师食谱中将cURL请求转换为http_请求

在厨师食谱中将cURL请求转换为http_请求,curl,sonarqube,chef-infra,chef-recipe,Curl,Sonarqube,Chef Infra,Chef Recipe,有人可以帮助我如何将以下cURL请求转换为http\u请求 curl -X POST -u admin:admin -F backup=@'/tmp/backup2.xml' -v #{sonarqube_rest_uri}/qualityprofiles/restore 我的Vagrant box的/tmp文件夹中有backup2.xml。我可以通过编写bash脚本来发送请求,但我希望使用http\u请求资源的方法更简洁。您可以尝试以下方法: http_request 'Post back

有人可以帮助我如何将以下
cURL
请求转换为
http\u请求

curl -X POST -u admin:admin -F backup=@'/tmp/backup2.xml' -v #{sonarqube_rest_uri}/qualityprofiles/restore 
我的Vagrant box的/tmp文件夹中有backup2.xml。我可以通过编写bash脚本来发送请求,但我希望使用
http\u请求
资源的方法更简洁。

您可以尝试以下方法:

http_request 'Post backup xml' do
  headers ({
    'Content-Type' => 'multipart/form-data',
    'AUTHORIZATION' => "Basic #{Base64.encode64('admin:admin')}"
  })
  action :post
  url "#{sonarqube_rest_uri}/qualityprofiles/restore"
  message ::File.read("/tmp/backup2.xml")
end
该标志表示您需要
多部分/表单数据
标题。您还需要
-u admin:admin
的授权头,Chef文档对此有很好的了解。操作和url非常简单。最后,用
::file.read将文件内容作为消息读取

但是,关于
多部分/表单数据
内容类型的问题表明,这种类型的内容可能不适用于
http\u请求
。但是,希望这能帮助您理解如何将
curl
请求转换为
http\u请求