温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Loadrunner进行http接口压力测试

发布时间:2020-07-31 14:08:57 来源:网络 阅读:2593 作者:cvv54 栏目:软件技术

附件来自百度。



脚本正文:

/*

 * 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 < 0) {
				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();
	}
}



附件:http://down.51cto.com/data/2367948
向AI问一下细节
推荐阅读:
  1. LoadRunner
  2. LR测试HTTP接口

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI