Example usage for io.vertx.core.http HttpClient post

List of usage examples for io.vertx.core.http HttpClient post

Introduction

In this page you can find the example usage for io.vertx.core.http HttpClient post.

Prototype

HttpClientRequest post(String requestURI, Handler<AsyncResult<HttpClientResponse>> responseHandler);

Source Link

Document

Create an HTTP POST request to send to the server at the default host and port, specifying a response handler to receive the response

Usage

From source file:examples.HTTPExamples.java

License:Open Source License

public void example34(Vertx vertx, String body) {
    HttpClient client = vertx.createHttpClient();

    HttpClientRequest request = client.post("some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    });//from w w  w  .j a  v a  2s .  c  o m

    // Now do stuff with the request
    request.putHeader("content-length", "1000");
    request.putHeader("content-type", "text/plain");
    request.write(body);

    // Make sure the request is ended when you're done with it
    request.end();

    // Or fluently:

    client.post("some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    }).putHeader("content-length", "1000").putHeader("content-type", "text/plain").write(body).end();

    // Or event more simply:

    client.post("some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    }).putHeader("content-type", "text/plain").end(body);

}

From source file:examples.HTTPExamples.java

License:Open Source License

public void example42(HttpClient client) {

    HttpClientRequest request = client.post("some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    });//  w  w  w  .  j  a va  2s.c  om
    request.exceptionHandler(e -> {
        System.out.println("Received exception: " + e.getMessage());
        e.printStackTrace();
    });
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void statusCodeHandling(HttpClient client) {
    HttpClientRequest request = client.post("some-uri", response -> {
        if (response.statusCode() == 200) {
            System.out.println("Everything fine");
            return;
        }/*from   w ww  .java2  s. co  m*/
        if (response.statusCode() == 500) {
            System.out.println("Unexpected behavior on the server side");
            return;
        }
    });
    request.end();
}

From source file:org.entcore.common.neo4j.Neo4jRest.java

License:Open Source License

private void sendRequest(String path, Object body, boolean checkReadOnly,
        final Handler<HttpClientResponse> handler) throws Neo4jConnectionException {
    HttpClient client = null;
    if (checkReadOnly && ro) {
        String query = ((JsonObject) body).getString("query");
        if (query != null) {
            Matcher m = writingClausesPattern.matcher(query);
            if (!m.find()) {
                client = nodeManager.getSlaveClient();
            }//w w w  .  ja v  a  2 s.  com
        }
    }
    if (client == null) {
        client = nodeManager.getClient();
    }
    HttpClientRequest req = client.post(basePath + path, handler);
    req.headers().add("Content-Type", "application/json").add("Accept", "application/json; charset=UTF-8");

    final String b = Json.encode(body);

    req.exceptionHandler(event -> logger.error("Neo4j error in request : " + b, event));

    req.end(b);
}