本文整理匯總了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);
}