我有一个像
这样的场景 user logs in ( /login)
navigate to the reservations page to get all the reservation id (/reservations)
Through regular expression I retrieve all reservation ids like reservationids_1=19678406 etc...
navigate to the first reservation id (/reservation/${reservationids_1})
在它导航的每个页面中,HTTP标头管理器需要适用于该页面的handShakeKey,它基本上是url,secretKey,publicKey的组合。 (secretKey,publicKey都是静态的,但是url更改)
对于像(/ login,/ reservations)这样的静态网址,我在开头添加了一个BSF预处理器并声明变量,并在HTTP标头管理器中使用这些变量作为$ {handshakeKey_reservations},$ {handshakeKey_login}等工作完全没问题。
var urls = ["login", "reservations", "logout", "profile"];
for (var i = 0; i < urls.length; i++) {
var handShakeKeyForStaticUrls = CryptoJS.SHA1("/"+urls[i]+"abcdediiebneC"+"12345678");
handShakeKeyForStaticUrls = handShakeKeyForStaticUrls.toString(CryptoJS.enc.Base64);
vars.put("handshakeKey_"+urls[i], handShakeKeyForStaticUrls);
}
现在的问题是动态网址(/ reservation / $ {reservationid},/ reservation / $ {reservationid} / summary等.......)
作为一种解决方法,我尝试在每个动态网址HTTTP采样器之前放置一个BSF后处理器
//reservationid = "19678406";
reservationid = "${reservationids_1}";
vars.put ("val", reservationid);
vars.put ("type", typeof(reservationid));
var handShakeKeyForDynamicUrls = CryptoJS.SHA1( "/reservation/" + reservationid +"abcdeeee"+"12345678");
handShakeKeyForDynamicUrls = handShakeKeyForDynamicUrls.toString(CryptoJS.enc.Base64);
vars.put("handShakeKeyForDynamicUrls", handShakeKeyForDynamicUrls);
在HTTP标头管理器中我使用handshakeKey $ {handShakeKeyForDynamicUrls}
当我使用reservationid =“19678406”作为BSF采样器(javascript)中的硬编码时;
以其工作正常为例
GET https://<servername>/reservation/19678406
handshake key :- 21d1ce663d079b5583d76730f6f1477d8f6ae
Also in the debug sampler type and val coming as string and 19678406 which is OK
但是当我在BSF采样器(javascript)中使用reservationid =“$ {reservationids_1}”时;它失败了
GET https://<servername>/reservation/19678406
handshake key :- b607876d69f5d59c5258bcd5a2a064bbcf35
Also in the debug sampler type and val coming as string and 19678406
所以不明白两者是如何不同的。为什么失败了。如果我传递参数(在两种情况下都具有相同的字符串类型和值),而不是硬编码值,为什么它会失败。
对此有何看法?
注意: - 日志查看器中没有错误。
答案 0 :(得分:0)
我做了一个解决方法,它工作正常。
之前添加了另一个BSF采样器(BeanShell)并提到了
vars.put ("reservationid", "${reservationid_1}");
然后是下一个BSF后处理器(java脚本)
var handShakeKeyForDynamicUrls = CryptoJS.SHA1( "/reservation/${reservationid}" +"abcdeeee"+"12345678");
handShakeKeyForDynamicUrls = handShakeKeyForDynamicUrls.toString(CryptoJS.enc.Base64);
vars.put("handShakeKeyForDynamicUrls", handShakeKeyForDynamicUrls);