當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientBuilder.disableRedirectHandling方法代碼示例

本文整理匯總了Java中org.apache.http.impl.client.HttpClientBuilder.disableRedirectHandling方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientBuilder.disableRedirectHandling方法的具體用法?Java HttpClientBuilder.disableRedirectHandling怎麽用?Java HttpClientBuilder.disableRedirectHandling使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.impl.client.HttpClientBuilder的用法示例。


在下文中一共展示了HttpClientBuilder.disableRedirectHandling方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testHttpRequestGet

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
@Test
public void testHttpRequestGet() throws Exception {

    RequestConfig.Builder req = RequestConfig.custom();
    req.setConnectTimeout(5000);
    req.setConnectionRequestTimeout(5000);
    req.setRedirectsEnabled(false);
    req.setSocketTimeout(5000);
    req.setExpectContinueEnabled(false);

    HttpGet get = new HttpGet("http://127.0.0.1:54322/login");
    get.setConfig(req.build());

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setDefaultMaxPerRoute(5);

    HttpClientBuilder builder = HttpClients.custom();
    builder.disableAutomaticRetries();
    builder.disableRedirectHandling();
    builder.setConnectionTimeToLive(5, TimeUnit.SECONDS);
    builder.setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE);
    builder.setConnectionManager(cm);
    CloseableHttpClient client = builder.build();

    String s = client.execute(get, new ResponseHandler<String>() {

        @Override
        public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            assertEquals(301, response.getStatusLine().getStatusCode());
            return "success";
        }

    });
    assertEquals("success", s);

}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:37,代碼來源:HTTPStrictTransportSecurityIT.java

示例2: setRedirectStrategy

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
private void setRedirectStrategy(HttpClientBuilder httpClientBuilder) {
    RedirectStrategy redirectStrategy = config.getRedirectStrategy().getImplementation();
    if (redirectStrategy == null) {
        httpClientBuilder.disableRedirectHandling();
    } else {
        httpClientBuilder.setRedirectStrategy(redirectStrategy);
    }
}
 
開發者ID:vy,項目名稱:hrrs,代碼行數:9,代碼來源:ApacheHttpClientFactory.java

示例3: build

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
private CloseableHttpClient build(final Consumer<HttpClientBuilder> customizeBuilder) throws IOException {
	LOGGER.debug("HTTP {} {}", request, url);
	if (httpClient != null) {
		LOGGER.debug("Existing HttpClient re-used");
		return httpClient;
	}
	if (sslsf == null) {
		sslsf = createSSLConnectionSocketFactory(null, null, false);
	}

	HttpClientBuilder builder = HttpClients.custom()
			.setRetryHandler(new StandardHttpRequestRetryHandler(3, true) {
				@Override
				public boolean retryRequest(IOException exception,
						int executionCount, HttpContext context) {
					try {
						TimeUnit.SECONDS.sleep(3);
					} catch (InterruptedException e) {
					}
					return super.retryRequest(exception, executionCount,
							context);
				}
			}).setSSLSocketFactory(sslsf);
	if (username != null) {
		CredentialsProvider credsProvider = new BasicCredentialsProvider();
		credsProvider.setCredentials(
				new AuthScope(url.getHost(), url.getPort() == -1 ? url.getDefaultPort() : url.getPort()),
				new UsernamePasswordCredentials(username, password));

		builder.setDefaultCredentialsProvider(credsProvider);
	}
	if (disableRedirect) {
		builder.disableRedirectHandling();
	}

	addPreemptiveAuthorizationHeaders();

	if (customizeBuilder != null) {
		customizeBuilder.accept(builder);
	}
	if (!cookies.isEmpty()) {
		final CookieStore cookieStore = new BasicCookieStore();
		cookies.entrySet().stream().map(x -> new BasicClientCookie(x.getKey(), x.getValue())).forEach(cookieStore::addCookie);
		builder.setDefaultCookieStore(cookieStore);
	}
	return builder.build();
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:48,代碼來源:HttpClient.java

示例4: getUrlContents

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
protected Response getUrlContents(String theUrl, boolean useAuth, boolean followRedirects) {

        StringBuilder content = new StringBuilder();
        int code;

        try {

            HttpClientBuilder builder = HttpClientBuilder.create();
            if (!followRedirects) {
                builder.disableRedirectHandling();
            }

            if (useAuth) {
                CredentialsProvider provider = new BasicCredentialsProvider();
                UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "password");
                provider.setCredentials(AuthScope.ANY, credentials);
                builder.setDefaultCredentialsProvider(provider);
            }

            HttpClient client = builder.build();

            HttpResponse response = client.execute(new HttpGet(theUrl));
            code = response.getStatusLine().getStatusCode();

            if (response.getEntity() != null) {

                BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(response.getEntity().getContent())
                );

                String line;

                while ((line = bufferedReader.readLine()) != null) {
                    content.append(line + "\n");
                }
                bufferedReader.close();
            }

        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }

        return new Response(code, content.toString());
    }
 
開發者ID:eclipse,項目名稱:microprofile-health,代碼行數:46,代碼來源:SimpleHttp.java

示例5: handleRedirects

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
private void handleRedirects(RESTPool pool, HttpClientBuilder builder) {
    if (!pool.followRedirects())
        builder.disableRedirectHandling();
}
 
開發者ID:mercadolibre,項目名稱:java-restclient,代碼行數:5,代碼來源:HTTPCBuilder.java


注:本文中的org.apache.http.impl.client.HttpClientBuilder.disableRedirectHandling方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。