zoukankan      html  css  js  c++  java
  • URL编码转义,冒号和/不转,否则导致http链接失效

    URL含有中文需要转义

    参考 https://blog.csdn.net/benbenxiongyuan/article/details/10608095

    自己写一个

     1 public boolean checkURLFileIsExist(String stringURL){
     2         boolean isExist = false;
     3         String sEncodeURL;
     4 
     5         try{
     6             // URL内中文编码
     7             String s2 = Utils.encodeURIComponent(stringURL, "UTF-8");
     8             // :和/都会被编码,导致http链接就会失效处理
     9             sEncodeURL = s2.replaceAll("\%3A", ":").replaceAll("\%2F", "/");
    10             URL url = new URL(sEncodeURL);
    11             HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    12             int state = conn.getResponseCode();
    13             if(state == 200){
    14                 isExist  = true;
    15             }else{
    16                 isExist  = false;
    17             }
    18         }catch(Exception e){
    19             logger.error("checkURLFileIsExist occur exception:" + e);
    20             isExist = false;
    21             return isExist;
    22         }
    23         return isExist;
    24     }
  • 相关阅读:
    sqlServer的主键只能自增不能手动增加
    TP函数
    TP复习17
    TP复习16
    TP复习15
    TP复习14
    TP复习13
    TP复习12
    TP复习11
    TP复习10
  • 原文地址:https://www.cnblogs.com/zhangcheng1/p/11174736.html
Copyright © 2011-2022 走看看