#!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)