获取当前第一级路径的 URL, 比如访问/xxx/xxx/aaa 返回的是/xxx
(URL url)
| 17 | * 获取当前第一级路径的 URL, 比如访问/xxx/xxx/aaa 返回的是/xxx |
| 18 | */ |
| 19 | public static String getUrlWithPath(URL url) { |
| 20 | |
| 21 | String urlRootPath = getUrlRootPath(url); |
| 22 | try { |
| 23 | URL tmpurl = new URL(getUrlWithoutFilename(url)); |
| 24 | String path = tmpurl.getPath(); |
| 25 | while (path.startsWith("/")) { |
| 26 | path = path.substring(1); |
| 27 | } |
| 28 | if (path.isEmpty()) { |
| 29 | return urlRootPath; |
| 30 | } else { |
| 31 | return urlRootPath + "/" + path.substring(0, path.indexOf("/")); |
| 32 | } |
| 33 | } catch (MalformedURLException e) { |
| 34 | BurpExtender.getStderr().println(CommonUtils.exceptionToString(e)); |
| 35 | return urlRootPath; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * 获取根目录的 URL |
no test coverage detected