package io.vertx.example.webclient.send.multipartform;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.example.util.Runner;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;

/*
 * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
 */
public class Client extends AbstractVerticle {

  // Convenience method so you can run it in your IDE
  public static void main(String[] args) {
    Runner.runExample(Client.class);
  }

  @Override
  public void start() throws Exception {

    vertx.createHttpServer().requestHandler(req -> {
      System.out.println("Got form with content-type " + req.getHeader("content-type"));
      req.setExpectMultipart(true);
      req.endHandler(v -> {
        System.out.println("firstName: " + req.getFormAttribute("firstName"));
        System.out.println("lastName: " + req.getFormAttribute("lastName"));
        System.out.println("male: " + req.getFormAttribute("male"));
      });

    }).listen(8080, listenResult -> {
      if (listenResult.failed()) {
        System.out.println("Could not start HTTP server");
        listenResult.cause().printStackTrace();
      } else {

        WebClient client = WebClient.create(vertx);

        MultiMap form = MultiMap.caseInsensitiveMultiMap();
        form.add("firstName", "Dale");
        form.add("lastName", "Cooper");
        form.add("male", "true");

        client
          .post(8080, "localhost", "/")
          .putHeader("content-type", "multipart/form-data")
          .sendForm(form, ar -> {
            if (ar.succeeded()) {
              HttpResponse<Buffer> response = ar.result();
              System.out.println("Got HTTP response with status " + response.statusCode());
            } else {
              ar.cause().printStackTrace();
            }
          });
      }
    });
  }
}

@@ -597,651 +597,8 @@
 n %7B%0A
-%0A    vertx.createHttpServer().requestHandler(req -%3E %7B%0A      System.out.println(%22Got form with content-type %22 + req.getHeader(%22content-type%22));%0A      req.setExpectMultipart(true);%0A      req.endHandler(v -%3E %7B%0A        System.out.println(%22firstName: %22 + req.getFormAttribute(%22firstName%22));%0A        System.out.println(%22lastName: %22 + req.getFormAttribute(%22lastName%22));%0A        System.out.println(%22male: %22 + req.getFormAttribute(%22male%22));%0A      %7D);%0A%0A    %7D).listen(8080, listenResult -%3E %7B%0A      if (listenResult.failed()) %7B%0A        System.out.println(%22Could not start HTTP server%22);%0A        listenResult.cause().printStackTrace();%0A      %7D else %7B%0A%0A    
     
@@ -638,28 +638,24 @@
 te(vertx);%0A%0A
-    
     MultiMap
@@ -698,28 +698,24 @@
 iMap();%0A    
- 
-   
 form.add(%22fi
@@ -729,36 +729,32 @@
 %22, %22Dale%22);%0A    
-  
-  
 form.add(%22lastNa
@@ -769,20 +769,16 @@
 oper%22);%0A
-    
     form
@@ -800,20 +800,16 @@
 rue%22);%0A%0A
-    
     clie
@@ -817,20 +817,16 @@
 t%0A      
- 
-   
 .post(80
@@ -847,20 +847,16 @@
 %22, %22/%22)%0A
-    
       .p
@@ -903,20 +903,16 @@
 -data%22)%0A
-    
       .s
@@ -941,20 +941,16 @@
         
-    
 if (ar.s
@@ -963,20 +963,16 @@
 ed()) %7B%0A
-    
         
@@ -1028,20 +1028,16 @@
         
-   
- 
 System.o
@@ -1114,20 +1114,16 @@
         
-    
 %7D else %7B
@@ -1123,20 +1123,16 @@
  else %7B%0A
-    
         
@@ -1175,36 +1175,12 @@
     
-  
-  
 %7D%0A  
-        %7D);%0A      %7D%0A
     

remove the server in the Client.java