Use one of the following two options:
pathofURL = url.subString(0, url.lastIndexOf('/') + 1);
or if he has no request
pathofURL = url.getProtocol() + "://" + url.getAuthority() + url.getPath(); pathofURL = pathofURL.subString(0, pathofURL.lastIndexOf('/') + 1);
It has only a request.
pathofURL = url.getProtocol() + "://" + url.getAuthority() + url.getPath();
It has a request and a link
pathofURL = url.getProtocol() + "://" + url.getAuthority() + url.getFile();
Hope this helps, check the url and use any of the above.
source share