当前位置: 首页>>代码示例>>Java>>正文


Java WinHttpClients类代码示例

本文整理汇总了Java中org.apache.http.impl.client.WinHttpClients的典型用法代码示例。如果您正苦于以下问题:Java WinHttpClients类的具体用法?Java WinHttpClients怎么用?Java WinHttpClients使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WinHttpClients类属于org.apache.http.impl.client包,在下文中一共展示了WinHttpClients类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.http.impl.client.WinHttpClients; //导入依赖的package包/类
public final static void main(String[] args) throws Exception {

        if (!WinHttpClients.isWinAuthAvailable()) {
            System.out.println("Integrated Win auth is not supported!!!");
        }

        CloseableHttpClient httpclient = WinHttpClients.createDefault();
        // There is no need to provide user credentials
        // HttpClient will attempt to access current user security context through
        // Windows platform specific methods via JNI.
        try {
            HttpGet httpget = new HttpGet("http://winhost/");

            System.out.println("Executing request " + httpget.getRequestLine());
            CloseableHttpResponse response = httpclient.execute(httpget);
            try {
                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                EntityUtils.consume(response.getEntity());
            } finally {
                response.close();
            }
        } finally {
            httpclient.close();
        }
    }
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:ClientWinAuth.java

示例2: createHttpClient

import org.apache.http.impl.client.WinHttpClients; //导入依赖的package包/类
private HttpClient createHttpClient(Authentication auth, String verify, HttpHost target, Boolean postRedirects,
		String password, TrustStrategy keystoreTrustStrategy, HostnameVerifier keystoreHostnameVerifier,
		Proxy proxy) {
	Certificate certificate = new Certificate();
	Auth authHelper = new Auth();
	HttpClientBuilder httpClientBuilder = WinHttpClients.custom();
	Builder requestConfig = RequestConfig.custom();
	requestConfig.setCookieSpec(CookieSpecs.DEFAULT);

	logger.debug("Verify value: " + verify);
	logger.debug((new File(verify).getAbsolutePath()));

	if (new File(verify).exists()) {
		logger.debug("Loading custom keystore");
		httpClientBuilder.setSSLSocketFactory(
				certificate.allowAllCertificates(certificate.createCustomKeyStore(verify.toString(), password),
						password, keystoreTrustStrategy, keystoreHostnameVerifier));
	} else if (!Boolean.parseBoolean(verify.toString())) {
		logger.debug("Allowing all certificates");
		httpClientBuilder.setSSLSocketFactory(certificate.allowAllCertificates(null));
	}

	if (auth.isAuthenticable()) {
		httpClientBuilder.setDefaultCredentialsProvider(authHelper.getCredentialsProvider(auth, target));
	}

	if (proxy != null && proxy.isInUse()) {
		logger.debug("Enabling proxy");
		if (proxy.isAuthenticable()) {
			logger.debug("Setting proxy credentials");
			httpClientBuilder.setDefaultCredentialsProvider(
					authHelper.getCredentialsProvider(proxy.getAuth(), proxy.getHttpHost()));
		}
		requestConfig.setProxy(proxy.getHttpHost());
	}

	if (postRedirects) {
		httpClientBuilder.setRedirectStrategy(new CustomRedirectStrategy());
	}
	httpClientBuilder.setDefaultRequestConfig(requestConfig.build());

	return httpClientBuilder.build();
}
 
开发者ID:Hi-Fi,项目名称:httpclient,代码行数:44,代码来源:RestClient.java

示例3: timeout

import org.apache.http.impl.client.WinHttpClients; //导入依赖的package包/类
@Test(timeout=30000) // this timeout (in ms) needs to be extended if you're actively debugging the code
public void testNoInfiniteLoopOnSPNOutsideDomain() throws Exception {
    Assume.assumeTrue("Test can only be run on Windows", WinHttpClients.isWinAuthAvailable());

    // HTTPCLIENT-1545
    // If a service principal name (SPN) from outside your Windows domain tree (e.g., HTTP/example.com) is used,
    // InitializeSecurityContext will return SEC_E_DOWNGRADE_DETECTED (decimal: -2146892976, hex: 0x80090350).
    // Because WindowsNegotiateScheme wasn't setting the completed state correctly when authentication fails,
    // HttpClient goes into an infinite loop, constantly retrying the negotiate authentication to kingdom
    // come. This error message, "The system detected a possible attempt to compromise security. Please ensure that
    // you can contact the server that authenticated you." is associated with SEC_E_DOWNGRADE_DETECTED.

    final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
        .register(AuthSchemes.SPNEGO, new AuthSchemeProvider() {
            @Override
            public AuthScheme create(final HttpContext context) {
                return new WindowsNegotiateSchemeGetTokenFail(AuthSchemes.SPNEGO, "HTTP/example.com");
            }
        }).build();
    final CredentialsProvider credsProvider =
            new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider());
    final CloseableHttpClient customClient = HttpClientBuilder.create()
            .setDefaultCredentialsProvider(credsProvider)
            .setDefaultAuthSchemeRegistry(authSchemeRegistry).build();

    final HttpHost target = start();
    final HttpGet httpGet = new HttpGet("/");
    final CloseableHttpResponse response = customClient.execute(target, httpGet);
    try {
        EntityUtils.consume(response.getEntity());
    } finally {
        response.close();
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:35,代码来源:TestWindowsNegotiateScheme.java

示例4: createHttpClient

import org.apache.http.impl.client.WinHttpClients; //导入依赖的package包/类
private CloseableHttpClient createHttpClient(ServerInfo serverInfo)
{

	HttpClientBuilder builder = (useBuiltinWindowsAuthentication(serverInfo)) ? WinHttpClients.custom() : HttpClients.custom();
	HttpClientConnectionManager connMgr = createConnectionManagerIfNecessary();
	if (connMgr != null)
	{
		builder.setConnectionManager(connMgr);
	}
	builder.setUserAgent(userAgent);
	builder.useSystemProperties();

	return builder.build();
}
 
开发者ID:Esri,项目名称:geoevent-datastore-proxy,代码行数:15,代码来源:GeoEventDataStoreProxy.java


注:本文中的org.apache.http.impl.client.WinHttpClients类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。