英文:
how to use jmeter to send data using a http request
问题
I try to use Jmeter and a http request to send data to a controller using a function to create 5 new user with the same data.
the function inside the controlleur:
public Result create(Http.Request request){
var body = safeJsonBody(request);
var mandatory_params = Ref.of(List.of("username", "firstname", "email", "password", "phonenumber", "address"));
var maybeUsername = extractNonEmptyString(body, "username");
var maybeFirstname = extractNonEmptyString(body, "firstname");
var maybeEmail = extractEmail(body, "email");
var maybePassword = extractNonEmptyString(body, "password");
var hashedPassword = "";
if(!maybePassword.isEmpty())
{
var hash = hashFactory.mkHash(maybePassword.get(), Registration);
hashedPassword= hash.get().hash;
}
var maybePhonenumber = extractNonEmptyString(body, "phonenumber");
var maybeAddress = extractNonEmptyString(body, "address");
logger.warn("maybeUsername : " + maybeUsername);
logger.warn("maybeFirstname : " + maybeFirstname);
logger.warn("maybeEmail : " + maybeEmail);
logger.warn("maybePassword : " + maybePassword);
logger.warn("maybePhonenumber : " + maybePhonenumber);
logger.warn("maybeAddress : "+maybeAddress);
if ( maybeUsername.isEmpty() || maybeFirstname.isEmpty() || maybeEmail.isEmpty() || maybePassword.isEmpty()) {
checkIfIsPresent(mandatory_params,maybeUsername,"username");
checkIfIsPresent(mandatory_params,maybeFirstname,"firstname");
checkIfIsPresent(mandatory_params,maybeEmail,"email");
checkIfIsPresent(mandatory_params,maybePassword,"password");
checkIfIsPresent(mandatory_params,maybePhonenumber,"phonenumber");
checkIfIsPresent(mandatory_params,maybeAddress,"address");
return badRequest("Missing mandatory params: " + mandatory_params);
}
var tx = usersModel.upsert(maybeUsername.get(),maybeFirstname.get(),
maybeEmail.get(),hashedPassword,maybePhonenumber.get(),maybeAddress.get());
if (tx.isEmpty()){
logger.warn(tx.toString());
return internalServerError(stc_map_to_json(Map.of("status","error","message", "The user could not be created or updated.")).get());
}
return ok(tx.get());
}
I see "Missing mandatory params: Ref{val=[username, firstname, email, password, phonenumber, address]}" inside the response body in the View result tree I created so the data must be going to the right function.
And I try display the content of the request send to the controller by using a logger and it's weirdly display "POST /user/create"
英文:
I try to use Jmeter and a http request to send data to a controller using a function to create 5 new user with the same data.
the function inside the controlleur:
public Result create(Http.Request request){
var body = safeJsonBody(request);
var mandatory_params = Ref.of(List.of("username", "firstname", "email", "password", "phonenumber", "address"));
var maybeUsername = extractNonEmptyString(body, "username");
var maybeFirstname = extractNonEmptyString(body, "firstname");
var maybeEmail = extractEmail(body, "email");
var maybePassword = extractNonEmptyString(body, "password");
var hashedPassword = "";
if(!maybePassword.isEmpty())
{
var hash = hashFactory.mkHash(maybePassword.get(), Registration);
hashedPassword= hash.get().hash;
}
var maybePhonenumber = extractNonEmptyString(body, "phonenumber");
var maybeAddress = extractNonEmptyString(body, "address");
logger.warn("maybeUsername : " + maybeUsername);
logger.warn("maybeFirstname : " + maybeFirstname);
logger.warn("maybeEmail : " + maybeEmail);
logger.warn("maybePassword : " + maybePassword);
logger.warn("maybePhonenumber : " + maybePhonenumber);
logger.warn("maybeAddress : "+maybeAddress);
if ( maybeUsername.isEmpty() || maybeFirstname.isEmpty() || maybeEmail.isEmpty() || maybePassword.isEmpty()) {
checkIfIsPresent(mandatory_params,maybeUsername,"username");
checkIfIsPresent(mandatory_params,maybeFirstname,"firstname");
checkIfIsPresent(mandatory_params,maybeEmail,"email");
checkIfIsPresent(mandatory_params,maybePassword,"password");
checkIfIsPresent(mandatory_params,maybePhonenumber,"phonenumber");
checkIfIsPresent(mandatory_params,maybeAddress,"address");
return badRequest("Missing mandatory params: " + mandatory_params);
}
var tx = usersModel.upsert(maybeUsername.get(),maybeFirstname.get(),
maybeEmail.get(),hashedPassword,maybePhonenumber.get(),maybeAddress.get());
if (tx.isEmpty()){
logger.warn(tx.toString());
return internalServerError(stc_map_to_json(Map.of("status","error","message", "The user could not be created or updated.")).get());
}
return ok(tx.get());
}
I see "Missing mandatory params: Ref{val=[username, firstname, email, password, phonenumber, address]}" inside the response body in the View result tree I created so the data must be going to the right function.
And I try display the content of the request send to the controller by using a logger and it's weirdly display "POST /user/create"
答案1
得分: 1
{
"username": "userJM",
"firstname": "usernameJM",
"email": "userJM@gmail.com",
"password": "mdpJM",
"phonenumber": 12345678934,
"address": "150 rue jmeter"
}
在JMeter中,应该是类似这样的:
你可能还需要添加一个HTTP Header Manager并配置它以发送Content-Type头部,值为application/json
如果你不确定如何正确构建此请求,最简单的方法是使用JMeter的HTTP(S)测试脚本记录器进行录制
}
英文:
It looks like you need to send a JSON structure like:
{
"username": "userJM",
"firstname": "usernameJM",
"email": "userJM@gmail.com",
"password": "mdpJM",
"phonenumber": 12345678934,
"address": "150 rue jmeter"
}
In JMeter it would be something like:
You might also need to add a HTTP Header Manager and configure it to send Content-Type header with the value of application/json
If you're not sure how to properly build this or that request the easiest way is just recording it using JMeter's HTTP(S) Test Script Recorder
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论