我正在尝试使用 HttpClient 将文件上传/删除到 webdav 服务器。但是,每当我的文件名由 space 组成时,都没有工作。我收到一条错误消息“INVALID URI--- Escaped absolute path not valid”。
这是我的 URL = "http://localhost:8080/test file.txt"
private boolean delete(String fileName) {
HttpClient client = new HttpClient();
HttpHost host = new HttpHost(WEBDAV_URL, PORT_NUMBER);
client.getHostConfiguration().setHost(host);
DeleteMethod del = new DeleteMethod(WEBDAV_URL_COMPLETE + fileName);
try {
client.executeMethod(del);
return true;
} catch (HttpException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
我应该使用什么方法或 URL 解析来解决这个问题
谢谢
编辑,通过将空格替换为“%20”找到了解决方案。
**
URL.replaceAll(" ","%20")
**
最佳答案
我用这个得到了我想要的......
URL.replaceAll("","%20")
关于java - HttpClient = INVALID URI - 转义的绝对路径无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13652681/