本文整理汇总了Java中org.apache.http.client.methods.HttpRequestBase.setConfig方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestBase.setConfig方法的具体用法?Java HttpRequestBase.setConfig怎么用?Java HttpRequestBase.setConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.methods.HttpRequestBase
的用法示例。
在下文中一共展示了HttpRequestBase.setConfig方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestHttpGet
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public String requestHttpGet(String url_prex, String type) throws HttpException, IOException {
String url = url_prex + type;
HttpRequestBase method = this.httpGetMethod(url, "");
method.setConfig(requestConfig);
long start = System.currentTimeMillis();
HttpResponse response = client.execute(method);
long end = System.currentTimeMillis();
Logger.getGlobal().log(Level.INFO, String.valueOf(end - start));
HttpEntity entity = response.getEntity();
if (entity == null) {
return "";
}
InputStream is = null;
String responseData = "";
try {
is = entity.getContent();
responseData = IOUtils.toString(is, "UTF-8");
} finally {
if (is != null) {
is.close();
}
}
return responseData;
}
示例2: getResponseAsString
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static Optional<String> getResponseAsString(HttpRequestBase httpRequest, HttpClient client) {
Optional<String> result = Optional.empty();
final int waitTime = 60000;
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(waitTime).setConnectTimeout(waitTime)
.setConnectionRequestTimeout(waitTime).build();
httpRequest.setConfig(requestConfig);
result = Optional.of(client.execute(httpRequest, responseHandler));
} catch (HttpResponseException httpResponseException) {
LOG.error("getResponseAsString(): caught 'HttpResponseException' while processing request <{}> :=> <{}>", httpRequest,
httpResponseException.getMessage());
} catch (IOException ioe) {
LOG.error("getResponseAsString(): caught 'IOException' while processing request <{}> :=> <{}>", httpRequest, ioe.getMessage());
} finally {
httpRequest.releaseConnection();
}
return result;
}
示例3: addRequestConfig
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private void addRequestConfig(final HttpRequestBase base,
final SdkHttpFullRequest request,
final ApacheHttpRequestConfig requestConfig) {
final int connectTimeout = saturatedCast(requestConfig.connectionTimeout().toMillis());
final RequestConfig.Builder requestConfigBuilder = RequestConfig
.custom()
.setConnectionRequestTimeout(connectTimeout)
.setConnectTimeout(connectTimeout)
.setSocketTimeout(saturatedCast(requestConfig.socketTimeout().toMillis()))
.setLocalAddress(requestConfig.localAddress());
/*
* Enable 100-continue support for PUT operations, since this is
* where we're potentially uploading large amounts of data and want
* to find out as early as possible if an operation will fail. We
* don't want to do this for all operations since it will cause
* extra latency in the network interaction.
*/
if (SdkHttpMethod.PUT == request.method() && requestConfig.expectContinueEnabled()) {
requestConfigBuilder.setExpectContinueEnabled(true);
}
base.setConfig(requestConfigBuilder.build());
}
示例4: addRequestConfig
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private void addRequestConfig(final HttpRequestBase base,
final Request<?> request,
final HttpClientSettings settings) {
final RequestConfig.Builder requestConfigBuilder = RequestConfig
.custom()
.setConnectionRequestTimeout(settings.getConnectionPoolRequestTimeout())
.setConnectTimeout(settings.getConnectionTimeout())
.setSocketTimeout(settings.getSocketTimeout())
.setLocalAddress(settings.getLocalAddress());
/*
* Enable 100-continue support for PUT operations, since this is
* where we're potentially uploading large amounts of data and want
* to find out as early as possible if an operation will fail. We
* don't want to do this for all operations since it will cause
* extra latency in the network interaction.
*/
if (HttpMethodName.PUT == request.getHttpMethod() && settings.isUseExpectContinue()) {
requestConfigBuilder.setExpectContinueEnabled(true);
}
addProxyConfig(requestConfigBuilder, settings);
base.setConfig(requestConfigBuilder.build());
}
示例5: config
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private static void config(HttpRequestBase httpRequestBase) {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.setSocketTimeout(TIMEOUT)
.build();
httpRequestBase.setConfig(requestConfig);
}
示例6: getRequest
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public HttpRequestBase getRequest(){
String url = getUrl();
HttpRequestBase request = getRequest(url);
if(!headers.isEmpty()){
for(Entry<String,List<String>> header : headers.entrySet()){
for(String headerValue : header.getValue()){
request.addHeader(header.getKey(), headerValue);
}
}
}
if(entity != null && canHaveEntity()){
((HttpEntityEnclosingRequest) request).setEntity(entity);
}
if(timeoutMs != null || proxy != null){
Builder builder = RequestConfig.custom();
builder.setCookieSpec(CookieSpecs.STANDARD);
if(timeoutMs != null){
builder.setConnectTimeout(timeoutMs).setConnectionRequestTimeout(timeoutMs).setSocketTimeout(timeoutMs);
}
if(proxy != null){
builder.setProxy(proxy);
}
RequestConfig requestConfig = builder.build();
request.setConfig(requestConfig);
}
return request;
}
示例7: handlerRequestConfig
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
* @param connectTimeout
* @param socketTimeout
* @param httpRequestBase
*/
private void handlerRequestConfig(int connectTimeout, int socketTimeout, HttpRequestBase httpRequestBase) {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(connectTimeout)
.setConnectTimeout(connectTimeout)
.setSocketTimeout(socketTimeout).build();
httpRequestBase.setConfig(requestConfig);
}
示例8: setHttpParams
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static void setHttpParams(HttpRequestBase httpBase,
int connectMillisTimeout, int readMillisTimeout,
boolean handleRedirects) {
RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
.setConnectTimeout(connectMillisTimeout)
.setSocketTimeout(readMillisTimeout)
.setRedirectsEnabled(handleRedirects).build();
httpBase.setConfig(requestConfig);
httpBase.setHeader("accept-encoding", "gzip");
}
示例9: setProxy
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static void setProxy(HttpRequestBase method, Proxy proxy) {
method.setConfig(RequestConfig.custom().setProxy(new HttpHost(proxy.getHostname(), proxy.getPort())).build());
}
示例10: setHttpConfig
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
* 设置响应超时时间
*/
public void setHttpConfig(HttpRequestBase httpMethod){
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
httpMethod.setConfig(requestConfig);
}