Search code examples
groovycouchdbcloudant

how to prevent groovy RESTClient from url encoding a path with %2F codes in it?


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?


Solution

  • 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
                )