The image url contains Chinese, which leads to abnormal display on the IOS side

Originally, this part should be handled by the front-end, but the front-end is too lazy, so we can only use URLEncoder.encode to perform a transcoding on the front-end and back-end.
Let me talk about the reason first. According to the development of IOS and Android, Android will perform a transcoding of Chinese, but IOS will not, which leads to normal access to pictures on the Android side, but abnormal display on the IOS side.
The transcoding process is as follows, as symbols are also transcoded. So need to replace again

:// 转码后是 %3A%2F%2F
/ 转码后是  %2F
        String url = "https://kos-oss-test.oss-cn-hangzhou.aliyuncs.com/kite/企业微信截图_16387525355876_1638753098297.png";
        String encode = URLEncoder.encode(url,"utf-8");
        String replace = encode.replace("%3A%2F%2F", "://");
        String replace1 = replace.replace("%2F", "/");
        System.out.println(encode);
        System.out.println(replace1);

insert image description here

The transcoded url can be displayed normally, and the original Android terminal is not affected, because the Android transcoded is also the above one.

Follow up

It is found online that this transcoding is not perfect, and non-Chinese parts will also be transcoded, causing the link to become invalid. Only Chinese is transcoded. Method:
java:URLEncoder.encode only transcodes Chinese

Guess you like

Origin blog.csdn.net/RoyRaoHR/article/details/121783783