我在Java vert.x中有一个http服务器,并且从客户端收到一个带有字符串的请求,我需要将此字符串保存在变量中。如何访问发送的字符串?
public class Server extends AbstractVerticle {
private Router router;
private HttpServer httpServer = null;
@Override
public void start() throws Exception {
httpServer = vertx.createHttpServer();
httpServer.requestHandler(new Handler<HttpServerRequest>() {
@Override
public void handle(HttpServerRequest request) {
System.out.println("incoming request!");
Buffer fullRequestBody = Buffer.buffer();
if (request.method() == HttpMethod.POST) {
request.handler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
fullRequestBody.appendBuffer(buffer);
}
});
request.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
}
});
}
}
});
httpServer.listen(9999);
}
}
答案 0 :(得分:1)
public class Server extends AbstractVerticle {
private Router router;
private HttpServer httpServer = null;
@Override
public void start() throws Exception {
httpServer = vertx.createHttpServer();
httpServer.requestHandler(new Handler<HttpServerRequest>() {
@Override
public void handle(HttpServerRequest request) {
System.out.println("incoming request!");
Buffer fullRequestBody = Buffer.buffer();
if (request.method() == HttpMethod.POST) {
request.handler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
fullRequestBody.appendBuffer(buffer);
}
});
request.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
}
});
}
}
});
httpServer.listen(9999);
}
}