How to prevent groovy RESTClient from url encoding path with% 2F codes in it?
I have groovy code to make a GET request to the 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 message is sent to the server:
"GET /aaaa/xxxx%252Fyyyy HTTP/1.1"
When should it be:
"GET /aaaa/xxxx%2Fyyyy HTTP/1.1"
Groovy seems to be encoding the path - how can I prevent this?
+3
source to share
1 answer
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
)
+3
source to share