如果我收到响应超过 1 分钟(60 秒) - 无论如何我都会收到 504 超时错误。这些参数仅适用于减少 60 秒的时间。我需要反之亦然。你能帮我在 RestAssured 中设置超时吗?最好使用 RequestSpecBuilder
import io.restassured.config.HttpClientConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.specification.RequestSpecification;
import io.restassured.filter.log.LogDetail;
import io.restassured.filter.Filter;
import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import java.util.concurrent.TimeUnit;
public class SpecificationFactory {
public static RestAssuredConfig config = RestAssuredConfig.config()
.httpClient(HttpClientConfig.httpClientConfig()
.setParam("http.connection.timeout", (int) TimeUnit.SECONDS.toMillis(120))
.setParam("http.socket.timeout", (int) TimeUnit.SECONDS.toMillis(120))
.setParam("http.connection-manager.timeout", (int) TimeUnit.SECONDS.toMillis(120)));
private SpecificationFactory() {
}
public static RequestSpecification getDefaultRequestSpecification(String serviceName) {
return new RequestSpecBuilder()
.setConfig(config)
.setBaseUri(UrlConfig.getUrl(ENV, serviceName))
.addHeader(Headers.AUTHORIZATION_HEADER, String.format(Headers.AUTHORIZATION_BEARER, ACCESS_TOKEN))
.setContentType(ContentType.JSON)
.setAccept(ContentType.JSON)
.log(LogDetail.ALL)
.addFilter(new RequestLoggingFilter())
.addFilter(new ResponseLoggingFilter())
.build()
.filter(new AllureRestAssured());
}
}
```
I tried to increase timeout in my RestAssured class by setting the params, but it won't help
504 是服务器端错误(从 5 开始)。
请在此处查看此特定错误的详细信息:https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504
因此无法在 HTTP 客户端控制服务器超时配置。