我正在使用模拟服务器来模拟外部服务器。但是,第一个网址是正确模拟的,但不是第二个网址:
mockServer = startClientAndServer(1080);
mockServerClient = new MockServerClient("localhost", 1080);
mockServerClient
.when(
request()
.withMethod("GET")
.withPath("/myurl1/"),
exactly(1)
)
.respond(
response()
.withStatusCode(200)
.withBody("OK")
);
mockServerClient
.when(
request()
.withMethod("GET")
.withPath("/myurl2/"),
unlimited()
)
.respond(
response()
.withStatusCode(200)
.withBody("true")
);
有关如何做的任何想法?我没有在网上找到任何例子。
答案 0 :(得分:0)
尝试前进,看看会发生什么。它应该是这样的:
mockServer = startClientAndServer(1080);
mockServerClient = new MockServerClient("localhost", 1080);
mockServerClient
.when(
request()
.withMethod("GET")
.withPath("/myurl1/"),
exactly(1)
)
.respond(
response()
.withStatusCode(200)
.withBody("OK")
);
.forward(
forward()
.withHost("/myurl12")
.withPort(80)
.withScheme(HTTP)
);