loadrunner java http_Loadrunner进行http接口压力测试

附件来自百度。

脚本正文:

/*

* LoadRunner Java script. (Build: _build_number_)

*

* Script Description:

*

*/

import lrapi.lr;

public class Actions

{

public int init() throws Throwable {

return 0;

}//end of init

public int action() throws Throwable {

com.CTLPTest ct1 = new com.CTLPTest();

ct1.main(null);

return 0;

}//end of action

public int end() throws Throwable {

return 0;

}//end of end

}

jar包内容:package com;

import java.io.InputStream;

import java.net.HttpURLConnection;

import java.net.URL;

import java.security.cert.X509Certificate;

import java.util.Properties;

import java.util.Random;

import javax.net.ssl.HostnameVerifier;

import javax.net.ssl.SSLSession;

import javax.net.ssl.X509TrustManager;

public class CTLPTest

{

public static void main(String[] args)

{

CTLPTest lbs = new CTLPTest();

String ltpUrl = lbs.ltpRequestUrl();

System.out.println("ltpUrl:"+ltpUrl);

System.out.println("lbs.ltpRequestUrl(ltpUrl):"+lbs.ltpRequestUrl(ltpUrl));

}

public int ltpRequestUrl(String ltpRequestUrl)

{

int returnCount = -1;

try

{

URL url = new URL(ltpRequestUrl);

Properties prop = System.getProperties();

System.setProperty("http.proxyHost", "proxy.com");

System.setProperty("http.proxyPort", "80");

//http

HttpURLConnection http = (HttpURLConnection)url.openConnection();

http.setUseCaches(false);

http.connect();

//http

InputStream in = http.getInputStream();

//

byte[] b = new byte[in.available()];

in.read(b);

//

String res = new String(b);

System.out.println("res:");

System.out.println(res);

//ж,÷

int of = res.indexOf("resultCode");

if (of 

System.out.println("***************failure***********************");

returnCount = -1;

} else {

returnCount = 1;

}

}catch(Exception e){

System.out.println("Exception");

System.out.println(e);

returnCount = -1;

}

return returnCount;

}

public String ltpRequestUrl() {

StringBuilder param = new StringBuilder("http://xxx.xxx.com");

//param.append("userid-1");

//param.append("&appName=LBS&Apikey=D39hr1FgplZSjV2eNVW71wvbYbl8Mip4");

return param.toString();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值