간단한 GET
대해 일반 그루비를 사용할 수 있지만 : 당신에게 많은 유연성 (다른 HTTP 동사, 내용 유형 협상 ... 등)를 제공하지 않습니다 그러나
'https://xxx.xxx.xxx/xapplication/xwebhook/xxxx-xxxx'.toURL().text
. 대신 나는 매우 완벽한 라이브러리 인 HttpBuilder-NG을 사용할 것이고 Groovy 구문을 염두에두고 만들어졌습니다. 작업 JSON 예제에 대해서는
, 다음은 POST
요청에 JSON 본문을 보내고에 이동 맵으로 사용할 수 있습니다 응답, 다시 구문 분석 :
@Grab('io.github.http-builder-ng:http-builder-ng-okhttp:0.14.2')
import static groovy.json.JsonOutput.toJson
import static groovyx.net.http.HttpBuilder.configure
def posts = configure {
request.uri = 'https://jsonplaceholder.typicode.com'
request.uri.path = '/posts'
request.contentType = 'application/json'
request.body = toJson(title: 'food', body: 'bar', userId: 1)
}.post()
assert posts.title == 'foo'
당신이 무엇이든을 해봤를? –
다음 스레드가 내 문제를 해결했습니다. http://stackoverflow.com/questions/25692515/groovy-built-in-rest-http-client – Anveshak