Hi I have something like the following that makes a URL Connection
and retrieves the data. The problem is that when I hit a page that requires authentication first I get the login page. I'm unsure of how to pass a username and password in the URLConnection. I'm hitting a site that is using JAAS authenticaiton.
import java.net.URL;
import java.net.URLConnection;
.....
URL location = new URL("www.sampleURL.com");
URLConnection yc = location.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
data += inputLine + "\n";
in.close();
I tried something like this but it didn't seem to work...
URL url = new URL("www.myURL.com");
URLConnection connection = url.openConnection();
String login = "username:password";
String encodedLogin = new BASE64Encoder().encodeBuffer(login.getBytes());
connection.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin);