Recherche…


Introduction

Utilisation du client HTTP Groovy, exemples et pièges.

Demande GET

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

import groovyx.net.http.RESTClient

try {
    def restClient = new RESTClient("http://weathers.co")
    def response = restClient.get(path: '/api.php', query: ['city': 'Prague'])
    println "Status     : ${response.status}"
    println "Body       : ${response.data.text}"
} catch (Exception e) {
    println "Error      : ${e.statusCode}"
    println "Message    : ${e.response.data}"
}


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow