I am trying to make a java program that could I would give her a string, it would paste it to Hastebin(www.hastebin.com) and print the paste's URL to the console and this is the code I have: Main.java(Main class):
public class Main {
Hastebin hastebin;
static String randomString = "HELLO";
public static void main(String args[]) {
System.out.println(Hastebin.paste((randomString)));
}
}
My Hastebin.java class:
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Hastebin {
public static String paste(String content){
final HttpClient client = HttpClient.newHttpClient();
final HttpRequest request = HttpRequest.newBuilder(
URI.create("https://hastebin.com/documents")
).POST(HttpRequest.BodyPublisher.fromString(content).build());
final HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandler.asString());
final String responseContent = response.body();
final JSONObject responseJson = new JSONObject(responseContent);
final String key = responseJson.getString("key");
return "https://hastebin.com/" + key;
}
}
My errors:
Error:(14, 48) java: cannot find symbol symbol: method fromString(java.lang.String) location: interface java.net.http.HttpRequest.BodyPublisher Error:(17, 92) java: cannot find symbol symbol: method asString() location: interface java.net.http.HttpResponse.BodyHandler Error:(19, 15) java: cannot find symbol symbol: class JSONObject location: class Hastebin Error:(19, 45) java: cannot find symbol symbol: class JSONObject location: class Hastebin
I would really appreciate getting help.