Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

url - Uri Builder in android - '/' replaced by '%2F' and ":" is replaced by "%3A"

I want to build the following URI -

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

...

Builder builder = new Builder();
builder.scheme(Constants.URL_SCHEME);
builder.authority(host);
builder.appendPath(service + "/" +method);
return builder.build().toString();

where

  • URL_SCHEME - https
  • host - 10.112.88.182:8443/Vehicle/services/
  • service - socialService
  • method - login

When this code runs I get the following URI -

https://10.112.88.182%3A8443%2FVehicle%2Fservices%2F/socialService%2Flogin

/ is replaced by %2F and : is replaced by %3A

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...