Gradle 脚本要在没有任何 3rd 方插件的情况下调用 REST Web 服务,有什么指示吗? [英] Gradle Script To call a REST Web service without any 3rd party plugins, any pointers?
本文介绍了Gradle 脚本要在没有任何 3rd 方插件的情况下调用 REST Web 服务,有什么指示吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在没有任何 3rd 方插件的情况下调用 REST 服务作为构建脚本 (Gradle) 的一部分,我该如何使用 Groovy 来做到这一点?
Hi I need to call a REST service as part of the buildscript (Gradle) without any 3rd party plugins, how could I use Groovy to do that?
(我的第一次尝试)
repositories {
mavenCentral()
}
dependencies {
complie "org.codehaus.groovy.modules.http-builder:http-builder:0.5.2"
}
task hello {
def http = new HTTPBuilder("http://myserver.com:8983/solr/select?q=*&wt=json")
http.auth.basic 'username', 'password'
http.request(GET, JSON ) { req ->
}
}
推荐答案
在没有外部库的情况下从 groovy 调用 REST 的最简单方法是执行 CURL.下面是一个调用 Artifactory、获取 JSON 并解析它的示例:
The easiest way to call REST from groovy without external libraries is executing CURL. Here's an example of calling Artifactory, getting JSON back and parsing it:
import groovy.json.JsonSlurper
task hello {
def p = ['curl', '-u', '"admin:password"', ""http://localhost:8081/api/storage/libs-release-local?list&deep=1""].execute()
def json = new JsonSlurper().parseText(p.text)
}
这篇关于Gradle 脚本要在没有任何 3rd 方插件的情况下调用 REST Web 服务,有什么指示吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文