2017-07-22 160 views
-1

我使用的畢加索圖像載入庫,發現其不加載某些URL不加載網址中包含土耳其字符畢加索與土耳其字符

例如以下網址決策問題https://satis.ugur.com.tr/uploads/user_1122/images/ued%20buzdolabı%20görseli.png

試圖this但不工作

public static String encodeTurkishCharactersInUrl(String url) { 
     String[] list = new String[] {"ü","ç","ı","ö","ğ","ş"," ","Ü","Ç","İ","Ö","Ğ","Ş"}; 
     for (int i = 0; i< list.length ; i++) { 
      try { 
       url = url.replace(list[i], URLEncoder.encode(list[i],"UTF-8")); 
      } catch (UnsupportedEncodingException e) { 
       e.printStackTrace(); 
      } 
     } 

     return url; 
    } 

回答

0

我發現了一個解決方案,通過避免使用UTF8編碼的空白區域,並用%20手動替換所有空格,現在網址正在工作

public static String encodeTurkishCharactersInUrl(String url) { 
     String[] list = new String[]{"ü", "ç", "ı", "ö", "ğ", "ş", "", "Ü", "Ç", "İ", "Ö", "Ğ", "Ş"}; 
     for (int i = 0; i < list.length; i++) { 
      try { 
       url = url.replace(list[i], URLEncoder.encode(list[i], "UTF-8")); 
      } catch (UnsupportedEncodingException e) { 
       e.printStackTrace(); 
      } 
     } 
     url = url.replaceAll(" ", "%20"); 

     return url; 
    }