我正在尝试制作一个 java 程序,我可以给她一个字符串,它将它粘贴到 Hastebin(www.hastebin.com) 并将粘贴的 URL 打印到控制台,这是我拥有的代码: Main.java(主类):
public class Main {
Hastebin hastebin;
static String randomString = "HELLO";
public static void main(String args[]) {
System.out.println(Hastebin.paste((randomString)));
}
}
我的 Hastebin.java 类:
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;
}
}
我的错误:
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
我真的很感激能得到帮助。