title: post params with groovy httpbuilder in mailgun
body: <p>I am trying to invoke mailgun send message api. The following code works if I pass the params along with url - </p>
  
  <pre><code>String targetUrl = "https://api.mailgun.net/v2/my_domain_name/messages?from=fromAddress&amp;to=toAddress&amp;subject=sub&amp;text=random+message" 
  </code></pre>
  
  <p>But when I try to add these params in the body then it does not work. I keep getting bad request from mailgun.  - </p>
  
  <pre><code>String targetUrl = "https://api.mailgun.net/v2/my_domain_name/messages
  body = [from:"fromAddress", to:"toAddress", subject:"sub", text:"random message"]
  </code></pre>
  
  <p>Here is the full code - </p>
  
  <pre><code>def sendEmail(String mailBody, String sub, String toIds) {
      String targetUrl = "https://api.mailgun.net/v2/my_domain_name/messages"
      def http = new HTTPBuilder(targetUrl)
  
      http.request( groovyx.net.http.Method.POST, groovyx.net.http.ContentType.JSON) {
  
          body = [from:"fromAddress", to:"toAddress", subject:"sub", text:"random message"]
  
          headers = ['Authorization':"Basic " + "api:my_api_key".bytes.encodeBase64().toString()]
  
          response.success = { resp, reader -&gt;
              println "valid response: " + reader
          }
      }
  }
  </code></pre>
  
  <p>Thanks!</p>