0

I am using this code for GETting a JSON object from the URL using Groovy: the URL that I use is a HTTPS URL so when I test the code I get a 403 error, after Google it I understand that I need to use a HttpBuilder SSL but I don't understand how can I do it.

the code is :

def getJson(Integer id) {
    def adress = new HTTPBuilder("https://api.XXXY.com")

    def path="/vls/v1/etudiants/${id}?b=my&apiKey=99990"
    //Get request
    adresseServeur.request(Method.GET, JSON) {

        uri.path = path

        headers.Accept = 'application/json'
        // success response handler
        response.success = { resp, json ->
            retourJson = json
        }

        // failure response handler 
        response.failure = { resp ->
            println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
user2936743
  • 61
  • 5
  • 13
  • 1
    The code you've posted it too broken. You call the HTTPBuilder `adress` but then uses something called `adresseServeur` to perform a request, and you don't even close the blocks properly. Also, you don't need to set `headers.Accept` as you already did it when calling `request( GET, JSON )`. If you want more help, please provide a stacktrace and code that actually works. – Renato Mar 30 '14 at 19:16
  • 1
    One more thing: you shouldn't pass your query in the `uri.path`. Try using only `/vls/v1/etudiants/${id}` as your path, and then setting the query like this: `uri.query = [ b: 'my', apiKey: '99990' ]` – Renato Mar 30 '14 at 19:23

0 Answers0