0

我有一个像

 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)这样的静态 url,我在开头添加了一个 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 等......)

作为一种解决方法,我尝试在每个动态 url HTTP 采样器之前放置一个 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}

当我在 BSF 采样器(javascript)中硬编码使用 reservationid = "19678406" 时;

它的工作正常作为例子

 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 

所以不明白两者有什么不同。为什么它会失败。如果我传递一个参数(在两种情况下都具有相同的字符串类型和值),而不是硬编码值,为什么它会失败。

对此有任何想法吗?

注意:- 日志查看器中没有错误。

4

1 回答 1

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);
于 2013-10-09T09:22:07.820 回答