由於您使用Apache HTTPClient 4 implementation(默認值)是這樣的:
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.jmeter.protocol.http.control.AuthManager;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
import org.apache.jmeter.util.JMeterUtils;
import java.net.URL;
AuthManager authManager = ((HTTPSamplerProxy) ctx.getPreviousSampler()).getAuthManager();
CredentialsProvider credentialsProvider = ((AbstractHttpClient) client).getCredentialsProvider();
String localhost = JMeterUtils.getPropDefault("httpclient.localaddress", "");
authManager.setupCredentials(client, new URL("http://your.url"), credentialsProvider, localhost);
參考文獻:
感謝德米特里。我會檢查這個並回復你 – Richie