4

I have some groovy code to make a GET request against a server:

import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*

import groovyx.net.http.HTTPBuilder

def server = new RESTClient( 'https://myaccount.cloudant.com'  )

// the id contains a forward slash, i.e. xxxx/yyyy

response = server.get (path: 'aaaa/xxxx%2Fyyyy', 
         contentType: JSON, requestContentType: JSON)

However, the following is getting sent to the server:

"GET /aaaa/xxxx%252Fyyyy HTTP/1.1"

When it should be this:

"GET /aaaa/xxxx%2Fyyyy HTTP/1.1"

It seems like groovy is encoding the path - how can i prevent this?

Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • could you just replace the '%2F' with a space char in the path value you're passing to the get method? – bdkosher Dec 15 '14 at 17:20
  • 1
    the '%2F' is a forward slash, and needs to be encoded for the server to realise that it's not a path component. – Chris Snow Dec 15 '14 at 20:52

1 Answers1

5

This worked for me:

import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*
import groovyx.net.http.URIBuilder
import groovyx.net.http.HTTPBuilder

def server = new RESTClient( 'https://myaccount.cloudant.com' )

def uri = new URIBuilder(
    new URI( server.uri.toString() + '/aaaa/xxxx%2Fyyyy' )
    )

response = server.get (
            uri: uri, 
            requestContentType: JSON
            )
Chris Snow
  • 23,813
  • 35
  • 144
  • 309