current position:Home>Jenkins pipeline calls the httprequest plug-in to submit an HTTP request

Jenkins pipeline calls the httprequest plug-in to submit an HTTP request

2021-08-26 21:51:32 momingliu

 

#!groovy
def call(reqMode,url,reqBody){
  // call httpRequest plug-in unit 
  if(reqMode == 'POST'){

    response = httpRequest customHeaders: [[name: 'Content-Type', value: 'application/x-www-form-urlencoded;charset=UTF-8']], // Use customization header, Avoid default charset=ISO-8859-1 Leading to Chinese miscode . First use contentType: 'APPLICATION_FORM', In the output, it will show Conten-Type Content  // contentType: 'APPLICATION_FORM', //POST The format that the request must use 
                 httpMode: "POST",
                 requestBody:reqBody,
                 url:url
  }

  if(reqMode == 'GET'){
    response = httpRequest contentType: 'APPLICATION_JSON',
                 httpMode: "GET",
                 customHeaders: [
                         [name: "TOKEN", value: "B456skjasdjkf="]
                 ],
                 url:url
  }

  return [response.status,response.content]
}


  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.

def data=' Hello , Zhang San ' // If data Contains characters &, You need to use %26 Instead of
def url='http://msg.x.com/msg/rcemsg'
def textmod = "key=$key&content=$data"
textmod = new String(textmod.getBytes(),"UTF-8")
HttpReq('POST',url,textmod)

 
  • 1.

 

copyright notice
author[momingliu],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2021/08/20210826215129806t.html

Random recommended