Passing a JSON structure to an external URL which is also a Vaadin app


Is it possible to send a JSON structure to an external application (also a Vaadin Application) using something the following.


I know you can build the URL by putting parameters on it but I want to send the JSON as POST data.

Is that possible?

Thanks, John.

Yes, it’s possible. I’d generally recommend going directly from server to server instead of having the browser act as a middle man. See for example this article:

I would use a [HttpClient]
( or [JAX-RS Client]
( to send the post request. In the receiving Vaadin Application there should be a REST Controller to receive an handle the post request, for example with [Spring]

Thanks both for your suggestions.

Just so that it is clear I think I need to explain what I am trying to do a bit better.

I need to redirect the user’s browser from the server they are on to a new server that runs my vaadin application.
At the moment I am using the following

            String QUERYLINK = ""
            UI.getCurrent().getPage().executeJavaScript("\"" + QUERYLINK + "\", \"_self\");");

This works just fine and the user is now on the new server and I have passed in the data and the called application retrieves it.

I want to do exactly the same thing except I don’t want to pass the data params on the URL.
I need to re-direct the users browser to the new application on a different server but I want to pass a JSON structure in the body of the request.

I can use httpClient to create the POST request and I get a response from the Vaadin application but how do I trigger the equivalent of the “” piece so that the user browser re-directed to the new site as well and it is set up to engage with the vaadin application on the new server.

    doItButton.addClickListener(e-> {
            // UI.getCurrent().getPage().executeJs("\"" + LINK + "\", \"_self\");");

     * Create the post body. 
     * @return the the post body string
    private String createPostBody() {
        final JsonObject l_payRequest = Json.createObjectBuilder()
                .add("bu", "M1")
                .add("cmt", "ABC")
        MLOGGER.debug("Request: " + l_payRequest.toString());
        return l_payRequest.toString();

     * makePostRequest.
     * @return boolean 200 OK = true else false
    public final boolean makePostRequest() {
        int l_iHTTPResponse = 0;
        try {
            final HttpClient l_httpclient = HttpClientBuilder.create().build();
            final HttpPost l_httppost = new HttpPost("");

            final StringEntity l_postbody = new StringEntity(createPostBody());
            //Execute and get the response.
            final HttpResponse response = l_httpclient.execute(l_httppost);
  "HTTP response " + response.getStatusLine().getStatusCode());
            l_iHTTPResponse = response.getStatusLine().getStatusCode();
            if (l_iHTTPResponse == HttpURLConnection.HTTP_OK) {
                final String l_sResponse = EntityUtils.toString(response.getEntity());
                // System.out.println("response: " + l_sResponse);
            } else {
                throw new Exception("makePayment(): Did not get 200 back from executeMethod");
        } catch (Exception e) {
            MLOGGER.error("MakeSSLPostRequest() Exception : " + e.getMessage());
        return (l_iHTTPResponse == HttpURLConnection.HTTP_OK);

Oh thats a very different situation that was originally asked. Using a Client here will not help you. But neither will setting the location of the page, as that will not make a POST request.

I can only think of one way to navigate in a browser with a POST request and that is [submitting a form]
( I think it should be possible to add hidden input fields in the form holding the values you want to post, and make your button the submit button of the form.

I don’t think there is a Form component for Vaadin, but I found [this code example]
( that should help you with all aspects of this issue


Thanks a million for the pointer - that works just perfectly!

Best Regards