Uri Builder in android - '/' replaced by '/' and “:” is replaced by “:”

后端 未结 3 1114
夕颜
夕颜 2021-02-04 00:45

I want to build the following URI -

https://10.112.88.182:8443/Vehicle/services/socialService/login

...

Builder builder = new          


        
相关标签:
3条回答
  • 2021-02-04 01:07

    The solution is quite simple, simply use appendEncodedPath(), it will not encode your string, it just appends it as it is.

    0 讨论(0)
  • 2021-02-04 01:16

    Like laalto said, this is how Uri.Builder works but if you want to get the uri in a regular url form, like in your case: https://10.112.88.182:8443/Vehicle/services/socialService/login you can do:

    URL url = new URL(URLDecoder.decode(builder.build().toString(), "UTF-8"));
    
    0 讨论(0)
  • 2021-02-04 01:33

    That's how Uri.Builder works. It encodes non-safe URL characters with special meaning to their %xx hex values.

    To prevent encoding URI parts that are already properly encoded, use the encoded versions of builder functions:

    builder.encodedAuthority(host);
    builder.appendEncodedPath(service + "/" +method);
    

    But since all your URL parts are already ready and don't need any further encoding, it's easier to just use a regular StringBuilder to concatenate the parts.

    0 讨论(0)
提交回复
热议问题