本文整理匯總了Java中org.apache.http.client.config.CookieSpecs類的典型用法代碼示例。如果您正苦於以下問題:Java CookieSpecs類的具體用法?Java CookieSpecs怎麽用?Java CookieSpecs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CookieSpecs類屬於org.apache.http.client.config包,在下文中一共展示了CookieSpecs類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: OAuthHttpClient
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
public OAuthHttpClient(int maxConnection, int connectTimeout, int socketTimeout) {
PoolingHttpClientConnectionManager connectionManager =
new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.build());
// set max connection
connectionManager.setMaxTotal(maxConnection);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout)
.setSocketTimeout(socketTimeout)
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
.build();
httpClient = HttpClientBuilder.create()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
}
示例2: buildHttpClient
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
/**
* Builds a custom Http client with custom DNS resolution, disabling persistent cookie stores and with custom
* timeout values.
*
* @return An http client to be used to execute test requests to nginx.
*/
static CloseableHttpClient buildHttpClient() {
return HttpClients.custom()
.setConnectionManager(buildConnectionManager())
.setDefaultRequestConfig(RequestConfig.custom()
// Waiting for a connection from connection manager
.setConnectionRequestTimeout(100)
// Waiting for connection to establish
.setConnectTimeout(100)
.setExpectContinueEnabled(false)
// Waiting for data
.setSocketTimeout(200)
// Do not allow cookies to be stored between calls.
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
.build())
.setRetryHandler(buildRetryHandler())
.disableRedirectHandling().build();
}
示例3: generateClient
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
@Override
public CloseableHttpAsyncClient generateClient ()
{
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope (AuthScope.ANY),
new UsernamePasswordCredentials(serviceUser, servicePass));
RequestConfig rqconf = RequestConfig.custom()
.setCookieSpec(CookieSpecs.DEFAULT)
.setSocketTimeout(Timeouts.SOCKET_TIMEOUT)
.setConnectTimeout(Timeouts.CONNECTION_TIMEOUT)
.setConnectionRequestTimeout(Timeouts.CONNECTION_REQUEST_TIMEOUT)
.build();
CloseableHttpAsyncClient res = HttpAsyncClients.custom ()
.setDefaultCredentialsProvider (credsProvider)
.setDefaultRequestConfig(rqconf)
.build ();
res.start ();
return res;
}
示例4: generateClient
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
@Override
public CloseableHttpAsyncClient generateClient ()
{
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope (AuthScope.ANY),
new UsernamePasswordCredentials(username, password));
RequestConfig rqconf = RequestConfig.custom()
.setCookieSpec(CookieSpecs.DEFAULT)
.setSocketTimeout(Timeouts.SOCKET_TIMEOUT)
.setConnectTimeout(Timeouts.CONNECTION_TIMEOUT)
.setConnectionRequestTimeout(Timeouts.CONNECTION_REQUEST_TIMEOUT)
.build();
CloseableHttpAsyncClient res = HttpAsyncClients.custom ()
.setDefaultCredentialsProvider (credsProvider)
.setDefaultRequestConfig(rqconf)
.build ();
res.start ();
return res;
}
示例5: apiRequest
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
private HttpRequestBase apiRequest(String apiMethod, List<NameValuePair> params) {
HttpPost post = new HttpPost(getRestApiUrl(apiMethod));
post.setConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build());
List<NameValuePair> formFields = new ArrayList<>();
formFields.add(new BasicNameValuePair("api.token", myPassword));
formFields.addAll(params);
try {
post.setEntity(new UrlEncodedFormEntity(formFields, "UTF-8"));
}
catch (UnsupportedEncodingException ignored) {
// cannot happen
}
return post;
}
示例6: send
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
@Override
protected CloseableHttpResponse send(CloseableHttpClient httpClient, String base) throws Exception {
List<NameValuePair> formParams = new ArrayList<>();
for (String key : params.keySet()) {
String value = params.get(key);
formParams.add(new BasicNameValuePair(key, value));
}
HttpPost request = new HttpPost(base);
RequestConfig localConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD)
.build();
request.setConfig(localConfig);
request.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8"));
request.setHeader("Content-Type", "application/x-www-form-urlencoded"); //內容為post
return httpClient.execute(request);
}
示例7: HttpUtils
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
private HttpUtils(HttpRequestBase request) {
this.request = request;
this.clientBuilder = HttpClientBuilder.create();
this.isHttps = request.getURI().getScheme().equalsIgnoreCase("https");
this.config = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY);
this.cookieStore = new BasicCookieStore();
if (request instanceof HttpPost) {
this.type = 1;
this.builder = EntityBuilder.create().setParameters(new ArrayList<NameValuePair>());
} else if (request instanceof HttpGet) {
this.type = 2;
this.uriBuilder = new URIBuilder();
} else if (request instanceof HttpPut) {
this.type = 3;
this.builder = EntityBuilder.create().setParameters(new ArrayList<NameValuePair>());
} else if (request instanceof HttpDelete) {
this.type = 4;
this.uriBuilder = new URIBuilder();
}
}
示例8: toHttpUriRequest
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
public HttpUriRequest toHttpUriRequest() {
LOGGER.debug("in createRequestBuilder");
RequestBuilder requestBuilder = createRequestBuilder();
int timeout = httpServiceInfo.getTimeout();
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
.setConnectionRequestTimeout(timeout)
.setSocketTimeout(timeout)
.setConnectTimeout(timeout)
.setCookieSpec(CookieSpecs.IGNORE_COOKIES);
requestBuilder.setConfig(requestConfigBuilder.build());
if (StringUtils.isNoneEmpty(httpServiceInfo.getContentType())) {
requestBuilder.addHeader("Content-Type", httpServiceInfo.getContentType());
} else {
requestBuilder.addHeader("Content-Type", httpServletRequest.getContentType());
}
return requestBuilder.build();
}
示例9: post0
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
private static HttpUriRequest post0(String url, Map<String, String> params) {
RequestBuilder requestBuilder = RequestBuilder.post().setCharset(CHARSET).setUri(url);
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
.setConnectionRequestTimeout(TIMEOUT)
.setSocketTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT).setCookieSpec(CookieSpecs.IGNORE_COOKIES);
requestBuilder.setConfig(requestConfigBuilder.build());
if (params != null && params.size() > 0) {
List<NameValuePair> nvList = new ArrayList<>();
for (Map.Entry<String, String> param : params.entrySet()) {
Object value = param.getValue();
if (value == null) {
continue;
}
nvList.add(new BasicNameValuePair(param.getKey(), value.toString()));
}
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nvList, CHARSET);
requestBuilder.setEntity(formEntity);
}
requestBuilder.addHeader("Connection", "Keep-Alive");
return requestBuilder.build();
}
示例10: HttpTransportClient
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
public HttpTransportClient(int retryAttemptsNetworkErrorCount, int retryAttemptsInvalidStatusCount) {
this.retryAttemptsNetworkErrorCount = retryAttemptsNetworkErrorCount;
this.retryAttemptsInvalidStatusCount = retryAttemptsInvalidStatusCount;
CookieStore cookieStore = new BasicCookieStore();
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(SOCKET_TIMEOUT_MS)
.setConnectTimeout(CONNECTION_TIMEOUT_MS)
.setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
.setCookieSpec(CookieSpecs.STANDARD)
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(MAX_SIMULTANEOUS_CONNECTIONS);
connectionManager.setDefaultMaxPerRoute(MAX_SIMULTANEOUS_CONNECTIONS);
httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setDefaultCookieStore(cookieStore)
.setUserAgent(USER_AGENT)
.build();
}
示例11: NestSession
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
public NestSession(String username, String password) throws LoginException {
super();
theLine = null;
theBody = null;
response = null;
theUsername = new String(username);
thePassword = new String(password);
log.info("Starting Nest login...");
retry = 0;
// Trust own CA and all self-signed certs
sslcontext = SSLContexts.createDefault();
// Allow TLSv1 protocol only
sslsf = new SSLConnectionSocketFactory(
sslcontext,
new String[] { "TLSv1" },
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
globalConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD)
.build();
_login();
}
示例12: send
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
@Override
protected CloseableHttpResponse send(CloseableHttpClient httpClient, String base) throws Exception {
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
for (String key : params.keySet()) {
String value = params.get(key);
formparams.add(new BasicNameValuePair(key, value));
}
HttpPost request = new HttpPost(base);
RequestConfig localConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD)
.build();
request.setConfig(localConfig);
request.setEntity(new UrlEncodedFormEntity(formparams, "UTF-8"));
request.setHeader("Content-Type", "application/x-www-form-urlencoded"); //內容為post
return httpClient.execute(request);
}
示例13: createHttpClient
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
public static CloseableHttpClient createHttpClient(final int maxRedirects) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
s_logger.info("Creating new HTTP connection pool and client");
final Registry<ConnectionSocketFactory> socketFactoryRegistry = createSocketFactoryConfigration();
final BasicCookieStore cookieStore = new BasicCookieStore();
final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connManager.setDefaultMaxPerRoute(MAX_ALLOCATED_CONNECTIONS_PER_ROUTE);
connManager.setMaxTotal(MAX_ALLOCATED_CONNECTIONS);
final RequestConfig requestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.DEFAULT)
.setMaxRedirects(maxRedirects)
.setSocketTimeout(DEFAULT_SOCKET_TIMEOUT)
.setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT)
.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT)
.build();
return HttpClientBuilder.create()
.setConnectionManager(connManager)
.setRedirectStrategy(new LaxRedirectStrategy())
.setDefaultRequestConfig(requestConfig)
.setDefaultCookieStore(cookieStore)
.setRetryHandler(new StandardHttpRequestRetryHandler())
.build();
}
示例14: createHttpClient
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
protected CloseableHttpClient createHttpClient(Map<String, Object> parameters)
{
HttpClientBuilder clientBuilder = HttpClients.custom();
// single connection
BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager();
clientBuilder.setConnectionManager(connManager);
// ignore cookies for now
RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
clientBuilder.setDefaultRequestConfig(requestConfig);
setAuthentication(parameters, clientBuilder);
CloseableHttpClient client = clientBuilder.build();
return client;
}
示例15: ProcessConnection
import org.apache.http.client.config.CookieSpecs; //導入依賴的package包/類
public ProcessConnection(ProcessDirector director, PhantomJSProcess process)
{
this.process = process;
HttpClientBuilder clientBuilder = HttpClients.custom();
// single connection
BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager();
clientBuilder.setConnectionManager(connManager);
RequestConfig requestConfig = RequestConfig.custom()
// ignore cookies for now
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
.setSocketTimeout(director.getRequestTimeout()).build();
clientBuilder.setDefaultRequestConfig(requestConfig);
this.httpClient = clientBuilder.build();
}