rest - 使用 groovy-wslite 从 CURL 请求发出 post 请求
问题描述
嗨,我有以下 CURL 请求,我想使用 groovy-wslite 库将其包含在 groovy 脚本中,以使请求正常工作。
curl -s -X POST -k -u user:password https://artifactory_url/api/search/aql -H 'Content-Type: text/plain' -d 'items.find({"type":"file","repo":{"$eq": "my-repo-name"},"path":{"$match":"com/mycompany/product1/subcat/mob/*"},"name":{"$match":"*apk"}}).sort({"$desc":["path"]}).limit(1)'
解决方案
您可以使用http-builder-ng并且您的代码看起来像
compile 'io.github.http-builder-ng:http-builder-ng-CLIENT:1.0.4'
HttpBuilder.configure {
request.uri = 'https://artifactory_url/api/search/aql'
request.auth.basic 'un', 'pw'
request.contentType = 'text/plain'
}.post {
request.body = 'items.find({"type":"file","repo":{"$eq": "my-repo-name"},"path":{"$match":"com/mycompany/product1/subcat/mob/*"},"name":{"$match":"*apk"}}).sort({"$desc":["path"]}).limit(1)'
response.success { FromServer fs, Object body ->
println body
}
}
推荐阅读
- vim - 有没有办法通过按 Escape 来取消 fzf
- javascript - 在引导的 ejs 表单上显示服务器端验证错误消息
- javascript - 它不会让我更改昵称 discord.js
- json - Unity3D - 我如何解析嵌套的重复 Json
- linux - 如何在 EC2 实例中为节点应用程序设置环境变量
- coq - 三个列表之间关系的归纳顺序
- python-3.x - Selenium Java 脚本 Webelement
- python - Python密码生成
- javascript - HTTP API 在 AWS Lambda 测试环境之外返回未定义的值
- flutter - 带有新文件飞镖的页面路由