хочу получить данные с http запросом, но при входе на сайт нужно ввести пароль и логин. Выдает ошибку 401
Вот Код:
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) new URL(query).openConnection();
connection.setRequestMethod("GET");
connection.setUseCaches(false);
connection.setConnectTimeout(250);
connection.setConnectTimeout(250);
connection.connect();
StringBuilder sb = new StringBuilder();
if(HttpURLConnection.HTTP_OK == connection.getResponseCode()){
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) !=null) {
sb.append(line);
sb.append("\n");
}
System.out.println(sb.toString());
}else{
System.out.println("fail :" + connection.getResponseCode());
}
}catch (Throwable cause){
cause.printStackTrace();
}finally {
if (connection != null){
connection.disconnect();