我遇到了这个问题,我想模拟一个在页面加载期间调用的对第三方的 https ajax 调用。我们最初的wiremock设置是在http上完成的,因此我们得到了错误
was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint
要解决这个问题,我只需要启用 Wiremock 服务器以侦听安全端口(请参阅代码的粗体部分)。请参阅下面的 UtilityClass,它在每次测试之前开始停止 WireMock 服务器。
public class WireMockHook {
public static final int WIREMOCK_PORT_NUMBER = 8089;
public static final int WIREMOCK_SECURE_PORT_NUMBER = 8043;
public static final String WIREMOCK_HOST = "localhost";
private WireMockServer wireMockServer;
@Before(order = 0)
public void startWireMock() {
wireMockServer = new WireMockServer(wireMockConfig().httpsPort(WIREMOCK_SECURE_PORT_NUMBER).port(WIREMOCK_PORT_NUMBER));
wireMockServer.start();
configureFor(WIREMOCK_HOST, WIREMOCK_PORT_NUMBER);
}
@After(order = 0)
public void stopWireMock() {
wireMockServer.stop();
}
}