0

I am writing something like an image proxy where I receive URLs from my site front-end, and I download images , re-size them, and return smaller images for the front end and client to download from the "proxy". This means I need to take care of all-sorts of url patterns, this is why I chose to decode the given url and than encode it using URIUtils.decode:

private String fixUrl(String fromUrl) throws URIException {
    fromUrl = URIUtil.decode(fromUrl);
    fromUrl = URIUtil.encodeQuery(fromUrl);
    return fromUrl;
}

This should help me take care of urls that are already encoded. My problem is that some of the urls are double encoded, and from what I saw, URIUtils.decode, performs recursive decode and this means that in cases of double encoded urls I will get a bad url that does not work.

Is there a simple way to decode only once?

4

1 回答 1

0

我会尝试检查 URL 是否仍然包含 character %。如果它不包含任何%内容,则不会对其进行编码,您可以停止解码过程。

于 2012-08-26T14:56:20.733 回答