本文整理汇总了Java中org.apache.http.params.BasicHttpParams.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java BasicHttpParams.setParameter方法的具体用法?Java BasicHttpParams.setParameter怎么用?Java BasicHttpParams.setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.params.BasicHttpParams
的用法示例。
在下文中一共展示了BasicHttpParams.setParameter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultApacheHttpParams
import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
private static HttpParams getDefaultApacheHttpParams()
{
// Configuración necesaria del Apache
// Parámetros copiados de los parámetros por defecto de AndroidHttpClient.newInstance(...)
// podríamos crear un AndroidHttpClient y coger los parámetros pero el problema es que "hay que usarlo".
// http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/net/http/AndroidHttpClient.java?av=f
BasicHttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("http.useragent", "Apache-HttpClient/UNAVAILABLE (java 1.4)"); // Emulador 4.0.3 SE CAMBIARÁ más adelante
httpParams.setIntParameter("http.socket.timeout", 60 * 1000);
httpParams.setBooleanParameter("http.connection.stalecheck", false);
httpParams.setIntParameter("http.connection.timeout", 60 * 1000);
httpParams.setBooleanParameter("http.protocol.handle-redirects", false);
httpParams.setIntParameter("http.socket.buffer-size", 8192);
// AHORA cambiamos los que nos interesan para dejarlos por defecto
httpParams.setParameter("http.useragent", USER_AGENT); // Añadimos ItsNatDroidBrowser
return httpParams;
}
示例2: addHeaderAndParams
import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
protected static void addHeaderAndParams(final HttpRequestBase request, final Map<String, String> params) {
// add default header
request.addHeader("User-Agent", userAgent);
// add params
if (params != null) {
// map --> HttpParams
BasicHttpParams myParams = new BasicHttpParams();
for (String key : params.keySet()) {
myParams.setParameter(key, params.get(key));
}
request.setParams(myParams);
}
}
示例3: getHttpParams
import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
/**
* HTTP参数配置
* @return
*/
public BasicHttpParams getHttpParams(){
BasicHttpParams httpParams = new BasicHttpParams();
// 设置每个路由最大连接数
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(30);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute);
HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
// 从连接池中取连接的超时时间,设置为1秒
ConnManagerParams.setTimeout(httpParams, mTimeout);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS));
ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
// 读响应数据的超时时间
HttpConnectionParams.setSoTimeout(httpParams, mTimeout);
HttpConnectionParams.setConnectionTimeout(httpParams, mTimeout);
HttpConnectionParams.setTcpNoDelay(httpParams, true);
HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE);
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUserAgent(httpParams,userAgent);
//默认参数
HttpClientParams.setRedirecting(httpParams, false);
HttpClientParams.setCookiePolicy(httpParams,
CookiePolicy.BROWSER_COMPATIBILITY);
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
return httpParams;
}
示例4: __setHttpClientParams
import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
private void __setHttpClientParams(DefaultHttpClient httpClient)
{
BasicHttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT);
httpClient.setParams(params);
}
示例5: freeze
import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
/**
* Initialize the connection.
*/
synchronized void freeze() {
if (frozen) {
return;
}
if (userAgent == null) {
setDefaultUserAgent();
}
serviceMap = new HashMap<String, ServiceEndpoint>();
if (log.isDebugEnabled()) {
StringBuilder buf = new StringBuilder();
buf.append("Creating MwsConnection {");
buf.append("applicationName:");
buf.append(applicationName);
buf.append(",applicationVersion:");
buf.append(applicationVersion);
buf.append(",awsAccessKeyId:");
buf.append(awsAccessKeyId);
buf.append(",uri:");
buf.append(endpoint.toString());
buf.append(",userAgent:");
buf.append(userAgent);
buf.append(",connectionTimeout:");
buf.append(connectionTimeout);
if (proxyHost != null && proxyPort != 0) {
buf.append(",proxyUsername:");
buf.append(proxyUsername);
buf.append(",proxyHost:");
buf.append(proxyHost);
buf.append(",proxyPort:");
buf.append(proxyPort);
}
buf.append("}");
log.debug(buf);
}
BasicHttpParams httpParams = new BasicHttpParams();
httpParams.setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
HttpConnectionParams
.setConnectionTimeout(httpParams, connectionTimeout);
HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
HttpConnectionParams.setStaleCheckingEnabled(httpParams, true);
HttpConnectionParams.setTcpNoDelay(httpParams, true);
connectionManager = getConnectionManager();
httpClient = new DefaultHttpClient(connectionManager, httpParams);
httpContext = new BasicHttpContext();
if (proxyHost != null && proxyPort != 0) {
String scheme = MwsUtl.usesHttps(endpoint) ? "https" : "http";
HttpHost hostConfiguration = new HttpHost(proxyHost, proxyPort, scheme);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, hostConfiguration);
if (proxyUsername != null && proxyPassword != null) {
Credentials credentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
CredentialsProvider cprovider = new BasicCredentialsProvider();
cprovider.setCredentials(new AuthScope(proxyHost, proxyPort), credentials);
httpContext.setAttribute(ClientContext.CREDS_PROVIDER, cprovider);
}
}
headers = Collections.unmodifiableMap(headers);
frozen = true;
}
示例6: createHttpRequest
import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
private static HttpUriRequest createHttpRequest(boolean isInstantly, boolean isGet, String url, JSONObject json,
HeaderPair... headers)
{
url = encodingUrl(url);
if (!__isHttpsSupported())
{
url = url.replace("https", "http");
}
EspHttpRequest request = null;
if (isGet)
{
request = new EspHttpRequest(url, EspHttpRequest.METHOD_GET);
}
else
{
request = new EspHttpRequest(url, EspHttpRequest.METHOD_POST);
}
if (isInstantly)
{
BasicHttpParams params = new BasicHttpParams();
params.setParameter(EspHttpRequest.ESP_INSTANTLY, true);
request.setParams(params);
}
// Add Headers
for (int i = 0; i < headers.length; i++)
{
HeaderPair header = headers[i];
request.addHeader(header.getName(), header.getValue());
}
// Set Entity
if (json != null)
{
try
{
StringEntity se = new StringEntity(decoceJSON(json), HTTP.UTF_8);
request.setEntity(se);
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
return null;
}
}
return request;
}
示例7: init
import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
private void init()
{
BasicHttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT);
params.setParameter("timemout", 6);
this.setParams(params);
// set keep alive strategy
this.setKeepAliveStrategy(new ConnectionKeepAliveStrategy()
{
public long getKeepAliveDuration(HttpResponse response, HttpContext context)
{ // Honor 'keep-alive' header
HeaderElementIterator it =
new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext())
{
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout"))
{
try
{
return Long.parseLong(value) * 1000;
}
catch (NumberFormatException ignore)
{
}
}
}
Integer timeout = (Integer)context.getAttribute("timeout");
if (timeout != null)
{
return timeout.longValue();
}
HttpHost target = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if ("iot.espressif.cn".equalsIgnoreCase(target.getHostName()))
{
// Keep alive for 30 seconds when connecting to server
return 30 * 1000;
}
else
{
// otherwise keep alive for 8 seconds when connection to device
return 10 * 1000;
}
}
});
}
示例8: createClient
import org.apache.http.params.BasicHttpParams; //导入方法依赖的package包/类
public static DefaultHttpClient createClient(BasicHttpParams params, int maxRedirect) {
params.setParameter(ClientPNames.HANDLE_REDIRECTS, maxRedirect==0?Boolean.FALSE:Boolean.TRUE);
if(maxRedirect>0)params.setParameter(ClientPNames.MAX_REDIRECTS, new Integer(maxRedirect));
params.setParameter(ClientPNames.REJECT_RELATIVE_REDIRECT, Boolean.FALSE);
return new DefaultHttpClient(params);
}