如何从第二次重定向获得响应?

时间:2018-02-02 08:33:57

标签: redirect http-redirect rest-assured response.redirect

我正在使用放心,我正在尝试从重定向获得响应,所以我有一个没有SSL证书的请求,即域是http,服务器自动执行301(这是重定向)到一个https域(即200)。我想要做的是从https域获得响应,即来自200状态代码。不知道为什么,但是在使用这段代码时我得到了一个org.apache.http.client.ClientProtocolException:

protected RequestSpecification specRedirect() {
        RestAssuredConfig restAssuredConfig = RestAssuredConfig.config()
                .redirect(redirectConfig().followRedirects(true).and().maxRedirects(1))
                .objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory(
                        (aClass, s) -> new ObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
                ));
        RestAssured.useRelaxedHTTPSValidation();
        restAssuredConfig = restAssuredConfig.httpClient(httpClientConfig().setParam(PARAMETER_NAME, TIMEOUT_VALUE));
        RequestSpecification spec = new TestSpecificationImpl(
                new RequestSpecBuilder()
                        .setConfig(restAssuredConfig)
                        .setBaseUri(this.baseURI)
                        .setBasePath(this.basePath)
                        .addFilters(this.filters)
                        .addHeaders(this.headers)
                        .build(),
                new ResponseSpecBuilder()
                        .build()
        ).getRequestSpecification();

        if (cookies != null && useCookies) {
            spec.cookies(cookies);
        }
        return spec;
    }

我在测试中称这种方法如下:

public Response getUrl(Cookie cookie, Cookie cookie, String domain, String string, String string, String string) {
        return specRedirect()
                .cookie(cookie)
                .cookie(cookie)
                .get(domain + "/string/string/string" + string + "?string=" + string + "&string=" + string + string);
    }

有任何帮助吗? :)

0 个答案:

没有答案