如何访问字符串请求?

时间:2021-02-14 18:04:04

I have a http server in java vert.x and I get a request from the client with a string and I need to save this string in the variable How do I access the string that is sent ?

我在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);
    }

}

1 个解决方案

#1


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);
}

}

#1


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);
}

}