How to find out if string has already been URL encoded?

后端 未结 11 1036
死守一世寂寞
死守一世寂寞 2020-11-30 03:46

How could I check if string has already been encoded?

For example, if I encode TEST==, I get TEST%3D%3D. If I again encode last string, I

11条回答
  •  心在旅途
    2020-11-30 04:16

    Using Spring UriComponentsBuilder:

    import java.net.URI;
    import org.springframework.web.util.UriComponentsBuilder;
    
    private URI getProperlyEncodedUri(String uriString) {
        try {
            return URI.create(uriString);
        } catch (IllegalArgumentException e) {
            return UriComponentsBuilder.fromUriString(uriString).build().toUri();
        }
    }
    

提交回复
热议问题