Answers: <p>I would recommend against importing if at all possible. You can use built-in functionality to achieve the same results. Also be aware of "<a href="https://jenkins.io/doc/book/managing/script-approval/" rel="nofollow noreferrer">In-process Script Approval</a>"</p>
  
  <p><a href="https://stackoverflow.com/a/42662243/1678094">https://stackoverflow.com/a/42662243/1678094</a></p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>// GET
  def get = new URL("https://httpbin.org/get").openConnection();
  def getRC = get.getResponseCode();
  println(getRC);
  if(getRC.equals(200)) {
      println(get.getInputStream().getText());
  }
  
  
  // POST
  def post = new URL("https://httpbin.org/post").openConnection();
  def message = '{"message":"this is a message"}'
  post.setRequestMethod("POST")
  post.setDoOutput(true)
  post.setRequestProperty("Content-Type", "application/json")
  post.getOutputStream().write(message.getBytes("UTF-8"));
  def postRC = post.getResponseCode();
  println(postRC);
  if(postRC.equals(200)) {
      println(post.getInputStream().getText());
  }
  </code></pre>
  
  <p>You can also override the request method:</p>
  
  <p><a href="https://stackoverflow.com/a/32503192/1678094">https://stackoverflow.com/a/32503192/1678094</a></p>
  
  <pre class="lang-java prettyprint-override"><code>conn.setRequestProperty("X-HTTP-Method-Override", "PATCH");
  conn.setRequestMethod("POST");
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2018-02-21T20:01:17.247Z
Answers: Default built in module doesn't have a PATCH method. I was trying  to apply other workarounds, but they do not work with Jenkins groovy. I created related question on developer forum: https://stackoverflow.com/questions/48521559/java-lang-nullpointerexception-cannot-invoke-method-get-on-null-object
Answers: user54
Answers: CC BY-SA 3.0
Answers: 2018-02-21T21:51:57.203Z
Answers: Updated with an additional workaround.
Answers: casey vega
Answers: CC BY-SA 3.0
Answers: 2018-02-21T22:25:51.450Z
Answers: As I mentioned I tried workarounds and this one as well. It didn't work out for my case.
Answers: user54
Answers: CC BY-SA 3.0
Answers: 2018-02-21T19:28:59.827Z
Answers: 2018-02-21T21:49:58.077Z
Answers: 2018-02-21T21:49:58.077Z
Answers: casey vega
Body: <p>Did somebody had a chance to use http-builder-ng Groovy module in Jenkins pipeline? </p>
  
  <p>When I use this module with any kind of request/URL it always returns me null object when the same source code from my Desktop is being run fine. </p>
  
  <p>Here is debug output: </p>
  
  <pre><code>&lt;groovyx.net.http.UriBuilder$Basic@4bc2413c scheme=http port=-1 host=api.open-notify.org path=/astros.json query=[:] fragment=null userInfo=null parent=groovyx.net.http.UriBuilder$ThreadSafe@69c6847a useRawValues=null&gt;
  </code></pre>
  
  <p>The older version of this module developed by groovy.codehouse works fine, but it doesn't have some methods which I need. </p>
  
Tags: <jenkins-pipeline><groovy><java><jenkins2>
Title: Compatibility of http-builder-ng Groovy module with Jenkins 2
UserDisplayName: user54
ThreadText: # Compatibility of http-builder-ng Groovy module with Jenkins 2
  
  (Asked by: username_0 on 2018-01-30)
  
  Did somebody had a chance to use http-builder-ng Groovy module in Jenkins pipeline?
  
  When I use this module with any kind of request/URL it always returns me null object when the same source code from my Desktop is being run fine.
  
  Here is debug output:
  
  ```
  <groovyx.net.http.UriBuilder$Basic@4bc2413c scheme=http port=-1 host=api.open-notify.org path=/astros.json query=[:] fragment=null userInfo=null parent=groovyx.net.http.UriBuilder$ThreadSafe@69c6847a useRawValues=null>
  
  ```
  
  The older version of this module developed by groovy.codehouse works fine, but it doesn't have some methods which I need.
  
  **Tags:** jenkins-pipeline, groovy, java, jenkins2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-02-21. Score: 1
  
  I would recommend against importing if at all possible. You can use built-in functionality to achieve the same results. Also be aware of "[In-process Script Approval](https://jenkins.io/doc/book/managing/script-approval/)"
  
  <https://stackoverflow.com/a/42662243/1678094>
  
  ```java
  // GET
  def get = new URL("https://httpbin.org/get").openConnection();
  def getRC = get.getResponseCode();
  println(getRC);
  if(getRC.equals(200)) {
      println(get.getInputStream().getText());
  }
  
  // POST
  def post = new URL("https://httpbin.org/post").openConnection();
  def message = '{"message":"this is a message"}'
  post.setRequestMethod("POST")
  post.setDoOutput(true)
  post.setRequestProperty("Content-Type", "application/json")
  post.getOutputStream().write(message.getBytes("UTF-8"));
  def postRC = post.getResponseCode();
  println(postRC);
  if(postRC.equals(200)) {
      println(post.getInputStream().getText());
  }
  
  ```
  
  You can also override the request method:
  
  <https://stackoverflow.com/a/32503192/1678094>
  
  ```java
  conn.setRequestProperty("X-HTTP-Method-Override", "PATCH");
  conn.setRequestMethod("POST");
  
  ```
  
  > **Comments:**
  > **username_0**: Default built in module doesn't have a PATCH method. I was trying  to apply other workarounds, but they do not work with Jenkins groovy. I created related question on developer forum: https://stackoverflow.com/questions/48521559/java-lang-nullpointerexception-cannot-invoke-method-get-on-null-object  
  > **username_1**: Updated with an additional workaround.  
  > **username_0**: As I mentioned I tried workarounds and this one as well. It didn't work out for my case.  
  
  ---
  
  