grails-plugins / grails-rest-client-builder

REST client plugin that uses Spring's RestTemplate
http://grails.org/plugin/rest-client-builder
Apache License 2.0
65 stars 32 forks source link

URL's containing a URL encoded space (%20) return a 404 #25

Open 4np opened 10 years ago

4np commented 10 years ago

Hi Graeme,

I am using the plugin to consume a Jenkins instance, but some of the view names in there contain (out of my control) spaces. These result in URLs containing spaces (e.g. http://my.jenkins.instance.com/job/something/view/foo%20bar/api/json ). Such URLs fail due to a 404. I assume because the %20 get's url decoded and a request is done with a real space or something.

Example code:

        String url = "https://my.jenkins.instance.com/job/something/view/foo%20bar/api/json"
        def rest = new RestBuilder()
        def resp = rest.get(jsonUrl) {
            auth username, password
        }

        println rest.getStatusCode()
aruizca commented 9 years ago

+1 I am using the URIBuilder to generate a URL which correctly encodes the parameters. If I pass that URL to the RestBuilder instance it reencodes everything.

So for instance, if I generate a URL like this using the URIBuilder:

http://biocache.ala.org.au/ws/occurrences/search?q=cl22%3A%22New+South+Wales%22&facets=taxon_name&pageSize=0&flimit=50&foffset=0&fq=species_group%3A%22Mammals%22

the actual request looks something like this:

http://biocache.ala.org.au/ws/occurrences/search?q=cl22%253A%2522New%2BSouth%2BWales%2522&fq=species_group%253A%2522Mammals%2522

If I decode to UTF-8 before using the rest builder then it works unless there is an ampersand, "&", within the parameter values.

aruizca commented 9 years ago

Using the Groovy RESTClient for the time being. If I have time I will look into the problem and hopefully send a PR

yuri1969 commented 8 years ago

+1 Re-encoding is a bummer.