我正在尝试启动一个bukkit插件,允许您在线控制您的服务器!我虽然有轻微的错误。我不知道该怎么做。我将为网站编写代码,我只需要代码来处理http请求。请帮忙!
答案 0 :(得分:1)
我试图做这样的事情。您可以使用com.sun
个包,它非常有用,但@Deprecated
。我是这样做的:
Public class HttpProcessor {
public HttpProcessor(MainClass plug) {
HttpServer server = HttpServer.Create(new InetSocketAddress(9090), 0);
server.createContext("/returnstaticvalue", new RSVhandler());
}
static class RSVhandler implements HttpHandler {
public void handle (HttpExchange h) throws IOException {
h.getResponseHeaders().set("Access-Control-Allow-Origin", "*");
HttpProcessor.writeResponse(h, "The static value");
}
}
public static void writeResponse(HttpExchange httpExchange, String response) throws IOException {
httpExchange.sendResponseHeaders(200, response.length());
OutputStream os = httpExchange.getResponseBody();
os.write(response.getBytes());
os.close();
}
}