Jenkins Pipeline调用 httpRequest插件提交Http请求


 

#!groovy
def call(reqMode,url,reqBody){
  //调用httpRequest插件
  if(reqMode == 'POST'){

    response = httpRequest customHeaders: [[name: 'Content-Type', value: 'application/x-www-form-urlencoded;charset=UTF-8']], //使用自定义header,避免默认的charset=ISO-8859-1导致中文乱码。先使用contentType: 'APPLICATION_FORM',在输出内容中会显示Conten-Type内容 // contentType: 'APPLICATION_FORM', //POST请求必须使用的格式
                 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]
}


def data='你好,张三' //如果data中包含字符&,则需要用 %26 代替
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)

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM