title: Groovy script for Jenkins: execute HTTP request without 3rd party libraries
body: <p>I need to create a Groovy post build script in Jenkins and I need to make a request without using any 3rd party libraries as those can't be referenced from Jenkins.</p>
  
  <p>I tried something like this:</p>
  
  <pre><code>def connection = new URL( "https://query.yahooapis.com/v1/public/yql?q=" +
      URLEncoder.encode(
              "select wind from weather.forecast where woeid in " + "(select woeid from geo.places(1) where text='chicago, il')",
              'UTF-8' ) )
      .openConnection() as HttpURLConnection
  
  // set some headers
  connection.setRequestProperty( 'User-Agent', 'groovy-2.4.4' )
  connection.setRequestProperty( 'Accept', 'application/json' )
  
  // get the response code - automatically sends the request
  println connection.responseCode + ": " + connection.inputStream.text
  </code></pre>
  
  <p>but I also need to pass a JSON in the POST request and I'm not sure how I can do that. Any suggestion appreciated.</p>