public class HttpServerExample { public static void main(String[] args) throws Exception { AsyncHttpServer.create() .requestHandler(request -> { String response = "Hello, World!"; return Promise.of(HttpResponse.create() .withBody(response) .withHeader(HttpHeaders.CONTENT_TYPE, "text/plain") .withHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(response.length()))); }) .listen(8080) .then(server -> System.out.println("Server started")) .whenComplete(($, e) -> { if (e != null) { System.err.println("Server failed to start: " + e); } }) .join(); } }


上一篇:
下一篇:
切换中文