java vuser_java vuser

1、ider创建项目

9fe85b6b55b0719920e13a8038a8348e.png

f325f8c0fd6eaf04f2e60c8ae654cf29.png

f9fef866805b2de4db3b43fd5556e503.png

a0df5e78220b7d63819defd012cd89c2.png

8db2b8b26304a94f68e5e3d087a09412.png

27a4ba78415268b82bef9ffe38ca0b84.png

问题1、 导入HttpClientRequest方法,导入相关相关方法遇到查询不到结果

5364e821b70e2d98a223cbb7b2f544fd.png

在prom.xml文件中添加如下内容解决:

org.apache.httpcomponents

httpcore

4.4.10

org.apache.httpcomponents

httpclient

4.5.6

com.alibaba

dubbo

2.5.3

test

com.alibaba

dubbo

2.5.3

compile

com.alibaba

fastjson

1.2.58

test

com.alibaba

fastjson

1.2.58

compile

com.google.code.gson

gson

2.8.1

org.codehaus.jettison

jettison

1.4.0

test

org.codehaus.jettison

jettison

1.3.4

org.codehaus.jettison

jettison

1.3.4

test

org.codehaus.jettison

jettison

1.3.4

compile

611b2dda974fb6c19d44cfc3780735ac.png

前期准备工作到此完成

创建脚本TestYjzf 调试

import com.Test.HttpClientRequest;

import com.Test.MD5;

import org.codehaus.jettison.json.JSONException;

import org.codehaus.jettison.json.JSONObject;

public class TestYjzf {

public static void main(String[] args) throws JSONException {

// 定义登录URL地址

String login_url = "http://192.168.86.129:8080/mobile/api/user/login";

// 定义请求的参数

String login_data = "{\"mobile\":\"158\",\"password\":\"123456\"}";

// 调用HttpClientRequest类里面的sendpost方法

String PostResult = HttpClientRequest.sendPost(login_url, login_data);

System.out.println("登录返回:"+ PostResult);

JSONObject jsonobj = new JSONObject(PostResult);

int status = (int) jsonobj.getInt("code");

System.out.println("code:" +status);

// 获取token值

String token = (String) jsonobj.getJSONObject("data").get("token");

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

String modifypaypwd_url = "http://192.168.86.129:8080/mobile/api/user/resetpaypwd";

// 调用md5类里面的getmd5code这个方法

String newPasswod = MD5.GetMD5Code("123456");

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

String modifypaypwd_data = "{\"token\":\""+token+"\",\"password\":\""+newPasswod+"\"}";

String PostMd5Result = HttpClientRequest.sendPost(modifypaypwd_url, modifypaypwd_data);

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

}

}

打jar包

file  --  Project Structure --  Artifacts -- 添加JAR--选择From moudules with....--弹窗Module是工程名称,Main Class选择要打包的包名点击OK

2f1f320ed41283d5438b09d315c65c27.png

jar包位置C:\Users\duwk\IdeaProjects\TestMd5\out\artifacts\TestMd5_jar

然后点击Build --- Build Artifacts... ---

cddf66e144e922a8f2af7bf720782e8e.png

到此jar包就打好了,下一步创建LR javavuser协议脚本。

创建LR脚本后,在runtime setting  java class导入jar包

copy部分代码:

import lrapi.lr;

public class Actions

{

public int init() throws Throwable {

return 0;

}//end of init

public int action() throws Throwable {

String login_url = "http://192.168.86.129:8080/mobile/api/user/login";

// 定义请求的参数

String login_data = "{\"mobile\":\"158\",\"password\":\"123456\"}";

// 调用HttpClientRequest类里面的sendpost方法

String result = HttpClientRequest.sendPost(login_url, login_data);

System.out.println("登录返回:"+ result);

return 0;

}//end of action

public int end() throws Throwable {

return 0;

}//end of end

}

调试报错:

1713a4dc8c3c6434ec48b95a5bf0e270.png

原因是没有导入相应方法,导入方法解决:

import com.Test.HttpClientRequest;

import com.Test.MD5;

import org.codehaus.jettison.json.JSONException;

import org.codehaus.jettison.json.JSONObject;

GET请求获取订单列表:

a7854ac46c7dc691bf6a438446f353b4.png

报错404,原因是没有在url后面拼“?”

加上“?”后报错:参数错误,原因是参数类型书写方式错误,改为:String order_list_data = "token="+token;后访问成功

订单列表:

// 订单列表

String order_list_url = "http://192.168.86.129:8080/mobile/api/order/getorders?";

String order_list_data = "token="+token_UTF8;

lr.start_transaction("ORDER");

String order_list_result = HttpClientRequest.sendGet(order_list_url,order_list_data);

// System.out.println(order_list_result);

JSONObject order = new JSONObject(order_list_result);

int order_status = (int) order.getInt("code");

if(order_status == 0){

lr.output_message("**** succes ****");

lr.end_transaction("ORDER", lr.PASS);

}

else{

lr.output_message("**** failed ****");

lr.end_transaction("ORDER", lr.FAIL);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值