That of adding the user and password in the url http://user:[email protected]
is a slightly dirty shortcut that only some browsers implement (and it seems that less and less). It is not recommended. And it is logical that Java does not walk.
To connect with HTTP with authentication (Basic), there is several ways , but all resolve to code the string <usuario>:<clave>
in Base64 and add it as property "Authorization"
in the connection:
URL url = new URL(path);
String userPass = "username:password";
String basicAuth = "Basic " + Base64.encodeToString(userPass.getBytes(), Base64.DEFAULT);
//o String basicAuth = "Basic " + new String(Base64.encode(userPass.getBytes(), Base64.No_WRAP));
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.setRequestProperty("Authorization", basicAuth);
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();