如何从第一个请求中获取令牌并在第二个请求中使用它
HTTPSampler httpAuth = new HTTPSampler();
httpAuth.setDomain( baseUrl);
httpAuth.setPort(443);
httpAuth.setPath("/permissions");
httpAuth.setMethod("GET");
httpAuth.setName("HTTP Request One");
httpAuth.setProtocol("https");
httpAuth.setProperty(TestElement.TEST_CLASS, HTTPSampler.class.getName());
httpAuth.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());
类似:
HTTPSampler httpAuth = new HTTPSampler();
httpAuth.setDomain(baseUrl);
httpAuth.setPort(443);
httpAuth.setPath("/permissions");
httpAuth.setMethod("GET");
httpAuth.setName("HTTP Request One");
httpAuth.setProtocol("https");
httpAuth.setProperty(TestElement.TEST_CLASS, HTTPSampler.class.getName());
httpAuth.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());
RegexExtractor regularExpressionExtractor = new RegexExtractor();
regularExpressionExtractor.setName("Regular Expression Extractor");
regularExpressionExtractor.setRegex("(your-regular-expression-for-extracting-the-token-here)");
regularExpressionExtractor.setRefName("token");
regularExpressionExtractor.setMatchNumber(1);
regularExpressionExtractor.setTemplate("$1$");
regularExpressionExtractor.setProperty(TestElement.TEST_CLASS,RegexExtractor.class.getName());
regularExpressionExtractor.setProperty(TestElement.GUI_CLASS, RegexExtractorGui.class.getName());
testPlanTree.add(testPlan);
HashTree threadGroupHashTree = testPlanTree.add(testPlan, threadGroup);
HashTree httpRequestTree = threadGroupHashTree.add(httpAuth,regularExpressionExtractor);
threadGroupHashTree.add(httpRequestTree);