您可以使用兩種compoenent更多的信息來解決這個問題: -
- User Defined Variables
- BeanShell-PreProcessor
步驟1:在腳本中使用用戶定義的變量來保留計數器的日期,以便在做出特定的POST請求時不應使用相同的日期。

步驟2:使用變量在步驟1中所定義,和寫腳本來獲得獨特日期在預處理器。這個預處理器應該作爲孩子添加到特定的POST請求中。預處理器
示例代碼: -
import java.text.SimpleDateFormat;
import java.util.Date;
int dateCounter=Integer.parseInt(vars.get("dateCounter"));
Date currentDate = new Date();
SimpleDateFormat date = new SimpleDateFormat("dd/MMM/yyyy");
long milliseconds = (long) dateCounter * 24 * 60 * 60 * 1000;
Date previousDate = new Date(currentDate.getTime() - milliseconds);
String strDate = date.format(previousDate);
vars.put("date",strDate);
dateCounter = dateCounter - 1;
vars.put("dateCounter",Integer.toString(dateCounter));
請注意,我們使用的是最近的1000天的例子,你可以修改根據自己的需要。現在,這個date
-Jmeter變量可以用於整個線程組,並且一旦使用partilculare POST採樣器生成日期,將爲下一個請求生成一個新日期。
感謝您的解決方案。我能夠解決我的問題。 – user1169236