Answer the question
In order to leave comments, you need to log in
http request. Getting data?
I'm getting an http request, I sort of made my way to the site, but I get the following error:
Exception in thread "main" java.net.ProtocolException: Server redirected too many times (20)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1921)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
at java.base/java.net.URL.openStream(URL.java:1117)
at Main.main(Main.java:13)
class Main {
public static void main(String[] argv) throws Exception {
Authenticator.setDefault(new MyAuthenticator());
URL url = new URL("")
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while((str = in.readLine()) != null) {
//System.out.println(str);
}
in.close();
}
}
class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
String promptString = getRequestingPrompt();
System.out.println(promptString);
String hostname = getRequestingHost();
System.out.println(hostname);
InetAddress ipaddr = getRequestingSite();
System.out.println(ipaddr);
int port = getRequestingPort();
String username ="";
String password ="";
return new PasswordAuthentication(username, password.toCharArray());
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question