GuiDupas GuiDupas - 3 months ago 16
Android Question

Android URL - Incomplete path

I am trying to create a

URL
but it seems that when I create the
URL
it isn't created with the full path.

Creating the URL

url = new URL("https://api.plivo.com/v1/Account/" + authID + "/Message/");


When I get the URL path

System.out.println(url.getPath());


The result is:
I/System.out: /v1/Account/XXXXXXXXXXXXXXXX/Message/


Does anyone know how can I can solve this?

Answer

This is just printing out the "path" part of the URL (after the web address)

Try this to show what is happening, I think there is also a toString in url that will allow you to print the entire thing with just url

URL url = new URL("http://google.com/example");
System.out.println(url.getHost());
System.out.println(url.getPath());
System.out.println(url.getHost() + url.getPath());

This outputs

google.com
/example
google.com/example

Also see the reference

https://docs.oracle.com/javase/7/docs/api/java/net/URL.html#getPath()

Comments