使用groovy发送get请求



def tableName="20180601"  //参数1
def batchId="0531211200158235"//参数2


def conn="http://"+context.expand('${interfaceURL}')+":"+context.expand( '${interfacePort}')+"/logservice/api/getList/mtLog?"
def param="tableName="+tableName+"&batchId="+batchId
conn+=param

//def Authorization=testRunner.testCase.testSuite.project.getPropertyValue("Authorization");
  URL url = new URL(conn);
  //返回一个URLConnection对象,它表示到URL所引用的远程对象的连接
  HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection()
  //在这里设置一些属性,详细见UrlConnection文档,HttpURLConnection是UrlConnection的子类
  //设置连接超时为5秒
  httpURLConnection.setConnectTimeout(5000)
  //设定请求方式(默认为get)
  httpURLConnection.setRequestMethod("GET")
  //建立到远程对象的实际连接
  httpURLConnection.connect();
  //返回打开连接读取的输入流,输入流转化为StringBuffer类型,这一套流程要记住,常用
  BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()))
  String line = null
  StringBuffer stringBuffer = new StringBuffer()
  String json = "";
 while ((json = bufferedReader.readLine()) != null) {
     stringBuffer.append(json);
  }
  String rsp= new String(stringBuffer.toString().getBytes(),"UTF-8")
  log.info "Get请求返回的数据:"+rsp
  bufferedReader.close()
  httpURLConnection.disconnect()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值