本文整理匯總了Java中org.apache.http.client.params.HttpClientParams.setAuthenticating方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientParams.setAuthenticating方法的具體用法?Java HttpClientParams.setAuthenticating怎麽用?Java HttpClientParams.setAuthenticating使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.params.HttpClientParams
的用法示例。
在下文中一共展示了HttpClientParams.setAuthenticating方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: a
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
public static b a(String str) {
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, 8192);
HttpClientParams.setRedirecting(basicHttpParams, true);
HttpClientParams.setAuthenticating(basicHttpParams, false);
HttpProtocolParams.setUserAgent(basicHttpParams, str);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme(com.alipay.sdk.cons.b.a, SSLCertificateSocketFactory.getHttpSocketFactory(30000, null), WebSocket.DEFAULT_WSS_PORT));
ClientConnectionManager threadSafeClientConnManager = new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry);
ConnManagerParams.setTimeout(basicHttpParams, 60000);
ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(10));
ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
Security.setProperty("networkaddress.cache.ttl", "-1");
HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
return new b(threadSafeClientConnManager, basicHttpParams);
}
示例2: enableAuth
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
public static void enableAuth(final AbstractHttpClient client, final Keychain keychain, final KeyId keyId) {
if (client == null) {
throw new NullPointerException("client");
}
if (keychain == null) {
throw new NullPointerException("keychain");
}
client.getAuthSchemes().register(Constants.SCHEME, new AuthSchemeFactory() {
public AuthScheme newInstance(HttpParams params) {
return new Http4SignatureAuthScheme();
}
});
Signer signer = new Signer(keychain, keyId);
client.getCredentialsProvider().setCredentials(AuthScope.ANY, new SignerCredentials(signer));
client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,
Arrays.asList(Constants.SCHEME));
HttpClientParams.setAuthenticating(client.getParams(), true);
}
示例3: a
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
public static b a() {
if (b == null) {
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, true);
basicHttpParams.setBooleanParameter("http.protocol.expect-continue", false);
ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(30));
ConnManagerParams.setTimeout(basicHttpParams, 1000);
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, 16384);
HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
HttpClientParams.setRedirecting(basicHttpParams, true);
HttpClientParams.setAuthenticating(basicHttpParams, false);
HttpProtocolParams.setUserAgent(basicHttpParams, a);
try {
SocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
Scheme scheme = new Scheme(com.alipay.sdk.cons.b.a, socketFactory, WebSocket.DEFAULT_WSS_PORT);
Scheme scheme2 = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(scheme);
schemeRegistry.register(scheme2);
b = new b(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
} catch (Exception e) {
b = new b(basicHttpParams);
}
}
return b;
}
示例4: configureHttpClient
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
/**
* @param username
* the username to use, can be null to avoid adding user name and password
* @param password
* the password to use
* @return the http client configured with username and password
*/
private HttpClient configureHttpClient(String username, String password) {
DefaultHttpClient httpClient = new DefaultHttpClient();
if (username != null) {
Credentials defaultcreds = new UsernamePasswordCredentials(username, password);
httpClient.getCredentialsProvider().setCredentials(
new AuthScope(host, port, AuthScope.ANY_REALM), defaultcreds);
HttpClientParams.setAuthenticating(httpClient.getParams(), true);
}
HttpClientParams.setRedirecting(httpClient.getParams(), false);
return httpClient;
}
示例5: configureHttpClient
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
private static void configureHttpClient(HttpClient httpClient) {
HttpParams params = httpClient.getParams();
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setConnectionTimeout(params, DEFAULT_CONNECT_TIMEOUT_MILLIS);
HttpConnectionParams.setSoTimeout(params, DEFAULT_READ_TIMEOUT_MILLIS);
HttpConnectionParams.setSocketBufferSize(params, 8192);
ConnManagerParams.setTimeout(params, DEFAULT_GET_CONNECTION_FROM_POOL_TIMEOUT_MILLIS);
// Don't handle redirects automatically
HttpClientParams.setRedirecting(params, false);
// Don't handle authentication automatically
HttpClientParams.setAuthenticating(params, false);
}
示例6: downloadRemoteFile
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
/**
* This method will download the specified localFile to the local cache. Any
* directories that need to be created will be generated as a side-effect of
* this action. There is no discretion regarding whether the localFile
* currently exists or not, if a localFile exists in the specified location,
* it will be overwritten.
*
* If the localFile does not exist in the central repository, this method
* will throw an IOException and will not create a zero length localFile.
* However the directories that would have contained the localFile will be
* created.
*
* @return a copy of the remote localFile specified
* @throws IOException
* Exception will be thrown if the remote localFile does not
* exist.
*/
private void downloadRemoteFile(int socketTimeout) throws Exception {
if (remoteFile == null)
return;
// tell the client to use the credential we got as parameter
Authenticator authenticator = AuthenticationUtil.getAuthenticator();
if (authenticator != null) {
if (client instanceof AbstractHttpClient) {
((AbstractHttpClient) client).getCredentialsProvider().setCredentials(new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME), authenticator.getCredentials());
}
// state.setAuthenticationPreemptive(true);
}
final HttpGet get = new HttpGet(remoteFile.toString());
HttpClientParams.setAuthenticating(get.getParams(), true);
HttpClientParams.setRedirecting(get.getParams(), false);
HttpUtils.execute(client, get, new HttpUtils.HttpResponseHandler() {
@Override
public void handleResponse(HttpResponse response) throws Exception {
int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK) {
getRemoteFileFromStream(response.getEntity().getContent());
setModifiedTime(get);
}
}
});
}
示例7: configure
import org.apache.http.client.params.HttpClientParams; //導入方法依賴的package包/類
/**
* Configures the various parameters of the connection manager and the HTTP
* client.
*
* @param params
* The parameter list to update.
*/
protected void configure(HttpParams params) {
ConnManagerParams.setMaxTotalConnections(params, getMaxTotalConnections());
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(getMaxConnectionsPerHost()));
// Configure other parameters
HttpClientParams.setAuthenticating(params, false);
HttpClientParams.setRedirecting(params, isFollowRedirects());
HttpClientParams.setCookiePolicy(params, CookiePolicy.BROWSER_COMPATIBILITY);
HttpConnectionParams.setTcpNoDelay(params, getTcpNoDelay());
HttpConnectionParams.setConnectionTimeout(params, getConnectTimeout());
HttpConnectionParams.setSoTimeout(params, getSocketTimeout());
params.setIntParameter(ClientPNames.MAX_REDIRECTS, getMaxRedirects());
//-Dhttp.proxyHost=chlaubc.obs.pmi -Dhttp.proxyPort=8000 -Dhttp.nonProxyHosts=localhost|127.0.0.1|*.app.pmi
String httpProxyHost = getProxyHost();
if (httpProxyHost != null) {
if (StringUtils.isNotEmpty(getNonProxyHosts())) {
System.setProperty("http.nonProxyHosts", getNonProxyHosts());
} else {
System.getProperties().remove("http.nonProxyHosts");
}
System.setProperty("http.proxyPort", String.valueOf(getProxyPort()));
System.setProperty("http.proxyHost", httpProxyHost);
HttpHost proxy = new HttpHost(httpProxyHost, getProxyPort());
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
}