本文整理匯總了Java中org.apache.http.impl.client.LaxRedirectStrategy類的典型用法代碼示例。如果您正苦於以下問題:Java LaxRedirectStrategy類的具體用法?Java LaxRedirectStrategy怎麽用?Java LaxRedirectStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LaxRedirectStrategy類屬於org.apache.http.impl.client包,在下文中一共展示了LaxRedirectStrategy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: download
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
private static void download(String url, File destination)
throws IOException {
HttpUriRequest request = RequestBuilder
.get()
.setUri(url)
.addParameter("hostname",
MinecraftServer.getServer().getHostname())
.addParameter("port",
String.valueOf(MinecraftServer.getServer().getPort()))
.build();
CloseableHttpClient client = HttpClientBuilder.create()
.setRedirectStrategy(new LaxRedirectStrategy())
.setUserAgent("Uranium Updater").build();
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() != 200) {
client.close();
throw new IllegalStateException("Could not download " + url);
}
InputStream is = response.getEntity().getContent();
OutputStream os = new FileOutputStream(destination);
IOUtils.copy(is, os);
is.close();
os.close();
client.close();
}
示例2: constructHttpClient
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
protected CloseableHttpClient constructHttpClient() throws IOException {
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(20 * 1000)
.setSocketTimeout(20 * 1000)
.setMaxRedirects(20)
.build();
URL mmsc = new URL(apn.getMmsc());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
if (apn.hasAuthentication()) {
credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
}
return HttpClients.custom()
.setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
.setRedirectStrategy(new LaxRedirectStrategy())
.setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT))
.setConnectionManager(new BasicHttpClientConnectionManager())
.setDefaultRequestConfig(config)
.setDefaultCredentialsProvider(credsProvider)
.build();
}
示例3: gen
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
@Override
public CrawlerHttpClient gen(CrawlerHttpClientBuilder proxyFeedBackDecorateHttpClientBuilder) {
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setSoLinger(-1).setSoReuseAddress(false)
.setSoTimeout(ProxyConstant.SOCKETSO_TIMEOUT).setTcpNoDelay(true).build();
return proxyFeedBackDecorateHttpClientBuilder
.setDefaultSocketConfig(socketConfig)
// .setSSLSocketFactory(sslConnectionSocketFactory)
// dungproxy0.0.6之後的版本,默認忽略https證書檢查
.setRedirectStrategy(new LaxRedirectStrategy())
//注意,這裏使用ua生產算法自動產生ua,如果是mobile,可以使用
// com.virjar.vscrawler.core.net.useragent.UserAgentBuilder.randomAppUserAgent()
.setUserAgent(UserAgentBuilder.randomUserAgent())
//對於爬蟲來說,連接池沒啥卵用,直接禁止掉(因為我們可能創建大量HttpClient,每個HttpClient一個連接池,會把係統socket資源撐爆)
//測試開80個httpClient抓數據大概一個小時係統就會宕機
.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE)
.build();
}
示例4: newClosableCachingHttpClient
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
private static CloseableHttpClient newClosableCachingHttpClient(EventStoreSettings settings) {
final CacheConfig cacheConfig = CacheConfig.custom()
.setMaxCacheEntries(Integer.MAX_VALUE)
.setMaxObjectSize(Integer.MAX_VALUE)
.build();
settings.getCacheDirectory()
.mkdirs();
return CachingHttpClientBuilder.create()
.setHttpCacheStorage(new FileCacheStorage(cacheConfig, settings.getCacheDirectory()))
.setCacheConfig(cacheConfig)
.setDefaultRequestConfig(requestConfig(settings))
.setDefaultCredentialsProvider(credentialsProvider(settings))
.setRedirectStrategy(new LaxRedirectStrategy())
.setRetryHandler(new StandardHttpRequestRetryHandler())
.setKeepAliveStrategy(new de.qyotta.eventstore.utils.DefaultConnectionKeepAliveStrategy())
.setConnectionManagerShared(true)
.build();
}
示例5: getGithubZipball
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
public static String getGithubZipball(String owner, String repo, String destFolder) throws IOException {
CloseableHttpClient httpclient = HttpClients.custom()
.setRedirectStrategy(new LaxRedirectStrategy())
.build();
String urlForGet = "https://api.github.com/repos/" + owner + "/" + repo + "/zipball/";
HttpGet get = new HttpGet(urlForGet);
HttpResponse response = httpclient.execute(get);
InputStream is = response.getEntity().getContent();
String filePath = destFolder + File.separator + repo + ".zip";
FileOutputStream fos = new FileOutputStream(new File(filePath));
int inByte;
while ((inByte = is.read()) != -1)
fos.write(inByte);
is.close();
fos.close();
return filePath;
}
示例6: createHttpClient
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的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();
}
示例7: constructHttpClient
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
protected CloseableHttpClient constructHttpClient()
throws IOException {
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(20 * 1000)
.setSocketTimeout(20 * 1000)
.setMaxRedirects(20)
.build();
URL mmsc = new URL(apn.getMmsc());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
if (apn.hasAuthentication()) {
credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
}
return HttpClients.custom()
.setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
.setRedirectStrategy(new LaxRedirectStrategy())
.setUserAgent("Android-Mms/2.0")
.setConnectionManager(new BasicHttpClientConnectionManager())
.setDefaultRequestConfig(config)
.setDefaultCredentialsProvider(credsProvider)
.build();
}
示例8: doGet
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
@Override
public void doGet(IHTTPSession session, Response response) {
try {
CloseableHttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
String url = session.getParms().get("image");
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0.3");
httpGet.addHeader("Accept-Encoding", "gzip");
CloseableHttpResponse imdbResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = imdbResponse.getEntity();
response.setChunkedTransfer(true);
response.setMimeType("image/jpeg");
response.setData(httpEntity.getContent());
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: fetchResult
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
public OmdbResponse fetchResult() {
OmdbResponse omdbResponse = null;
try {
CloseableHttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
List<NameValuePair> nameValuePairs = buildNameValuePair();
String url = "http://www.omdbapi.com/?" + URLEncodedUtils.format(nameValuePairs, "UTF-8");
log.debug("URL : " + url);
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0.3");
httpGet.addHeader("Accept-Encoding", "gzip");
CloseableHttpResponse imdbResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = imdbResponse.getEntity();
String content = EntityUtils.toString(httpEntity);
log.debug("content : " + content);
//FIXME to use jackson objectmapper
Gson gson = new GsonBuilder().serializeNulls().create();
omdbResponse = gson.fromJson(content, OmdbResponse.class);
} catch (Exception e) {
e.printStackTrace();
}
return omdbResponse;
}
示例10: download
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
private static void download(String url, File destination)
throws IOException {
HttpUriRequest request = RequestBuilder
.get()
.setUri(url)
.addParameter("hostname",
MinecraftServer.getServer().getHostname())
.addParameter("port",
String.valueOf(MinecraftServer.getServer().getPort()))
.build();
CloseableHttpClient client = HttpClientBuilder.create()
.setRedirectStrategy(new LaxRedirectStrategy())
.setUserAgent("KCauldron Updater").build();
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() != 200) {
client.close();
throw new IllegalStateException("Could not download " + url);
}
InputStream is = response.getEntity().getContent();
OutputStream os = new FileOutputStream(destination);
IOUtils.copy(is, os);
is.close();
os.close();
client.close();
}
示例11: constructHttpClient
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
protected CloseableHttpClient constructHttpClient() throws IOException {
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(20 * 1000)
.setSocketTimeout(20 * 1000)
.setMaxRedirects(20)
.build();
URL mmsc = new URL(apn.getMmsc());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
if (apn.hasAuthentication()) {
credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
}
return HttpClients.custom()
.setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
.setRedirectStrategy(new LaxRedirectStrategy())
.setUserAgent(SilencePreferences.getMmsUserAgent(context, USER_AGENT))
.setConnectionManager(new BasicHttpClientConnectionManager())
.setDefaultRequestConfig(config)
.setDefaultCredentialsProvider(credsProvider)
.build();
}
示例12: testSessionIdentityCache
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
@Test
public void testSessionIdentityCache() throws Exception {
HttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
HttpPost httpAuthenticate = new HttpPost(server.createUri("/j_security_check"));
List<NameValuePair> parameters = new ArrayList<>(2);
parameters.add(new BasicNameValuePair("j_username", "ladybird"));
parameters.add(new BasicNameValuePair("j_password", "Coleoptera"));
httpAuthenticate.setEntity(new UrlEncodedFormEntity(parameters));
assertSuccessfulResponse(httpClient.execute(httpAuthenticate), "ladybird");
for (int i = 0; i < 10; i++) {
assertSuccessfulResponse(httpClient.execute(new HttpGet(server.createUri())), "ladybird");
}
assertEquals(1, realmIdentityInvocationCount.get());
}
示例13: createClient
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
/**
* Creates asynchronous Apache HTTP client.
*
* @param settings
* settings to use to create client.
* @param conf
* configuration related to async connection.
* @return Instance of {@link CloseableHttpAsyncClient}.
*/
private CloseableHttpAsyncClient createClient(HttpSettings settings, ApacheHttpClientConfiguration conf) {
IOReactorConfig ioReactor = IOReactorConfig.custom().setIoThreadCount(conf.getMaxThreadCount()).build();
HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClients.custom()
.useSystemProperties()
// allow POST redirects
.setRedirectStrategy(new LaxRedirectStrategy()).setMaxConnTotal(conf.getMaxTotalConnectionCount()).setMaxConnPerRoute(conf.getMaxRouteConnectionCount()).setDefaultIOReactorConfig(ioReactor)
.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()).setDefaultRequestConfig(createDefaultRequestConfig(settings));
if (settings.getProxyUrl() != null) {
DefaultProxyRoutePlanner routePlanner = createProxyRoutePlanner(settings, httpClientBuilder);
httpClientBuilder.setRoutePlanner(routePlanner);
}
CloseableHttpAsyncClient httpClient = httpClientBuilder.build();
httpClient.start();
return httpClient;
}
示例14: createClient
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
private CloseableHttpClient createClient() {
final HttpClientBuilder builder = HttpClientBuilder.create();
// Provide username and password if specified
if (username != null) {
final BasicCredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(new AuthScope(new HttpHost(repositoryURL.getHost())),
new UsernamePasswordCredentials(username, password));
builder.setDefaultCredentialsProvider(credProvider);
}
// Follow redirects
builder.setRedirectStrategy(new LaxRedirectStrategy());
return builder.build();
}
示例15: HttpBuilder
import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
/**
* Creates a new {@link HttpBuilder}. Without additional input, the builder
* is set up to build {@link Http} instances with the following properties:
* <ul>
* <li>default connection timeout and socket timeout: 20 seconds</li>
* <li>server authentication/verification (on SSL): none</li>
* <li>client authentication: none</li>
* <li>default request content type: application/json</li>
* </ul>
* All of these settings can be modified through the builder's methods.
*/
public HttpBuilder() {
this.clientBuilder = HttpClients.custom();
this.clientBuilder.setRedirectStrategy(new LaxRedirectStrategy());
this.requestConfigBuilder = RequestConfig.copy(RequestConfig.DEFAULT);
this.requestConfigBuilder.setConnectTimeout(DEFAULT_CONNECTION_TIMEOUT);
this.requestConfigBuilder.setSocketTimeout(DEFAULT_SOCKET_TIMEOUT);
this.sslContextBuilder = SslContextBuilder.newBuilder();
verifyHostCert(false);
verifyHostname(false);
this.defaultHeaders = new HashMap<>();
contentType(ContentType.APPLICATION_JSON);
this.logger = Http.LOG;
}