I wrote an Java Program that query a API from haveibeenpwned.com. And nearly every time i get the output:
run:
Fehler
java.lang.RuntimeException: Failed : HTTP error code : 503
BUILD SUCCESSFUL (total time: 0 seconds)
That's looks like an DDOS Protection but in my Browser all works fine so i don't can explain that and i don't find any other errors.
My Code:
package checkpassword;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
public class CheckPassword
{
//Thats an old Email from Me ^^
final static String testMail = "[email protected]";
public static void main(String[] args)
{
// ArrayList<String> mailList = createEmailList();
//
// for(int i=0; i<mailList.size(); i++)
// {
System.out.println(getOutput(testMail));
// }
}
public static String getOutput( String Mail )
{
String output;
try
{
URL url = new URL("https://haveibeenpwned.com/api/breachedaccount/" + Mail);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200)
{
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
output = br.readLine();
conn.disconnect();
}catch (Exception ex)
{
output = "Fehler";
System.err.println(ex);
}
return output;
}
public static ArrayList createEmailList()
{
ArrayList<String> mailList = new ArrayList<>();
try
{
FileReader fr = new FileReader("C:/Users/s.kobe/Desktop/test.txt");
BufferedReader br = new BufferedReader(fr);
while(true)
{
String Zeile = br.readLine();
if(Zeile != null)
{
mailList.add(Zeile);
}else{
break;
}
}
br.close();
}catch(Exception ex)
{
System.err.println(ex);
}
return mailList;
}
}
Thanks for your help in advance
Sandro
//Some text that i reach the requirements to ask my Question because i think that i explain all important stuff