HttpClient = INVALID URI - Escaped absolute path not valid

david picture david · Nov 30, 2012 · Viewed 14.1k times · Source

I am trying to upload/delete a file to webdav server using HttpClient. However, none is working whenever I have a file name consist of space . I got a error message saying "INVALID URI--- Escaped absolute path not valid".

this my 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;
    }
}

is there any method or URL parse should I use to fix the problem

thanks

EDIT, FOUND the solution by replace space with "%20".

**

URL.replaceAll(" ","%20")

**

Answer

david picture david · Dec 18, 2012

I used this and get what I want...

URL.replaceAll(" ","%20")