title: Spring WebFlux, how can I debug my WebClient POST exchange?
body: <p>I am having trouble understanding what I've done wrong in constructing my WebClient request. I would like to understand what the actual HTTP request looks like. (e.g., dumping the raw request to console)</p>
  
  <pre><code>POST /rest/json/send HTTP/1.1
  Host: emailapi.dynect.net
  Cache-Control: no-cache
  Postman-Token: 93e70432-2566-7627-6e08-e2bcf8d1ffcd
  Content-Type: application/x-www-form-urlencoded
  
  apikey=ABC123XYZ&amp;from=example%40example.com&amp;to=customer1%40domain.com&amp;to=customer2%40domain.com&amp;to=customer3%40domain.com&amp;subject=New+Sale+Coming+Friday&amp;bodytext=You+will+love+this+sale.
  </code></pre>
  
  <p>I am using Spring5's reactive tools to build an API. I have a utility class that will send an email using Dyn's email api. I would like to use The new WebClient class to accomplish this (<strong>org.springframework.web.reactive.function.client.WebClient</strong>)</p>
  
  <p>The following command has been taken from : <a href="https://help.dyn.com/email-rest-methods-api/sending-api/#postsend" rel="noreferrer">https://help.dyn.com/email-rest-methods-api/sending-api/#postsend</a></p>
  
  <pre><code>curl --request POST "https://emailapi.dynect.net/rest/json/send" --data "apikey=ABC123XYZ&amp;from=example@example.com&amp;to=customer1@domain.com&amp;to=customer2@domain.com&amp;to=customer3@domain.com&amp;subject=New Sale Coming Friday&amp;bodytext=You will love this sale."
  </code></pre>
  
  <p>When I make the call in curl with real values, the email sends correctly, so I feel like I am generating my request incorrectly.</p>
  
  <p>My Send Command</p>
  
  <pre><code>public Mono&lt;String&gt; send( DynEmailOptions options )
  {
      WebClient webClient = WebClient.create();
      HttpHeaders headers = new HttpHeaders();
      // this line causes unsupported content type exception :(
      // headers.setContentType( MediaType.APPLICATION_FORM_URLENCODED );
      Mono&lt;String&gt; result = webClient.post()
          .uri( "https://emailapi.dynect.net/rest/json/send" )
          .headers( headers )
          .accept( MediaType.APPLICATION_JSON )
          .body( BodyInserters.fromObject( options ) )
          .exchange()
          .flatMap( clientResponse -&gt; clientResponse.bodyToMono( String.class ) );
      return result;
  }
  </code></pre>
  
  <p>My DynEmailOptions Class</p>
  
  <pre><code>import java.util.Collections;
  import java.util.Set;
  
  public class DynEmailOptions
  {
      public String getApikey()
      {
          return apiKey_;
      }
  
      public Set&lt;String&gt; getTo()
      {
          return Collections.unmodifiableSet( to_ );
      }
  
      public String getFrom()
      {
          return from_;
      }
  
      public String getSubject()
      {
          return subject_;
      }
  
      public String getBodytext()
      {
          return bodytext_;
      }
  
      protected DynEmailOptions(
          String apiKey,
          Set&lt;String&gt; to,
          String from,
          String subject,
          String bodytext
      )
      {
          apiKey_ = apiKey;
          to_ = to;
          from_ = from;
          subject_ = subject;
          bodytext_ = bodytext;
      }
  
      private Set&lt;String&gt; to_;
      private String from_;
      private String subject_;
      private String bodytext_;
      private String apiKey_;
  }
  </code></pre>