Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient = INVALID URI - Escaped absolute path not valid

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")

**

like image 647
david Avatar asked Nov 30 '12 20:11

david


2 Answers

I used this and get what I want...

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

like image 183
david Avatar answered Oct 05 '22 09:10

david


use java.net.URLEncoder.encode

or replace your spaces with '+'

like image 32
Stéphane Avatar answered Oct 05 '22 09:10

Stéphane