E
E
Egor Pavlov2018-06-18 07:06:17
Java
Egor Pavlov, 2018-06-18 07:06:17

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)

HERE CODE:
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());
        }
        }

I removed the password, login and site!!!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Satangelus, 2018-06-18
@Satangelus

Read here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question