When I try to retrieve the data from a pastebin and convert it to a string. It returns nothing. Just an empty line.
Code:
try {
URL url = new URL("http://pastebin.com/raw.php?i="+pasteKey);
String text = new BufferedReader(new InputStreamReader(url.openStream(),
StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
System.out.println(text);
} catch (IOException e) {
e.printStackTrace();
}
I have tried using GET but got the same result
EDIT: Found a solution. I first changed my code to:
try {
URL url = new URL("https://pastebin.com/raw/"+pasteKey);
Scanner scanner = new Scanner(url.openStream());
while (scanner.hasNext()){
System.out.println(scanner.nextLine());
}
scanner.close();
} catch (IOException e) {
e.printStackTrace();
}
Then I had to change this "http://pastebin.com/raw.php?i=" to this "https://pastebin.com/raw/" that removed an error I was having previously.
Hope this helped!