I was trying to connect to some host like this
url = new URL(urlString);
BufferedReader in = new BufferedReader(
new InputStreamReader(
url.openStream()));
but I always get MalformedException – permission denied, I need to provide username and password ( which I know ) but I don’t know how, there is no constructor in URL with those parametere neither setusername/password methods. Where to put username and password ?
I had do this in a previous project. In order to access a protected resource you need to use the Authenticator class.
The username and password go in the variables defined for them towards the end but they do not have to hard coded, you can externalize them using java properties.
Here is an old snippet