本文整理汇总了Java中org.apache.http.params.HttpParams.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java HttpParams.setParameter方法的具体用法?Java HttpParams.setParameter怎么用?Java HttpParams.setParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.params.HttpParams
的用法示例。
在下文中一共展示了HttpParams.setParameter方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAsString
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
public String getAsString(String url) throws Exception {
HttpGet get = new HttpGet(url);
HttpParams params = new BasicHttpParams();
params.setParameter("http.protocol.handle-redirects",false);
get.setParams(params);
HttpResponse r = httpClient.execute(get);
return EntityUtils.toString(r.getEntity());
}
示例2: createHTTPClient
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
private static AbstractHttpClient createHTTPClient() {
AbstractHttpClient client = new DefaultHttpClient();
String proxyHost = System.getProperty("https.proxyHost", "");
if (!proxyHost.isEmpty()) {
int proxyPort = Integer.parseInt(System.getProperty("https.proxyPort", "-1"));
log.info("Using proxy " + proxyHost + ":" + proxyPort);
HttpParams params = client.getParams();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
String proxyUser = System.getProperty(JMeter.HTTP_PROXY_USER, JMeterUtils.getProperty(JMeter.HTTP_PROXY_USER));
if (proxyUser != null) {
log.info("Using authenticated proxy with username: " + proxyUser);
String proxyPass = System.getProperty(JMeter.HTTP_PROXY_PASS, JMeterUtils.getProperty(JMeter.HTTP_PROXY_PASS));
String localHost;
try {
localHost = InetAddress.getLocalHost().getCanonicalHostName();
} catch (Throwable e) {
log.error("Failed to get local host name, defaulting to 'localhost'", e);
localHost = "localhost";
}
AuthScope authscope = new AuthScope(proxyHost, proxyPort);
String proxyDomain = JMeterUtils.getPropDefault("http.proxyDomain", "");
NTCredentials credentials = new NTCredentials(proxyUser, proxyPass, localHost, proxyDomain);
client.getCredentialsProvider().setCredentials(authscope, credentials);
}
}
return client;
}
示例3: getHttpClientInstance
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
public DefaultHttpClient getHttpClientInstance() {
if (this.httpClient != null) {
return this.httpClient;
}
HttpParams params = new BasicHttpParams();
params.setParameter("http.connection.timeout", CONNECTION_TIMEOUT);
params.setParameter("http.socket.timeout", SOCKET_TIMEOUT);
params.setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
params.setParameter("http.useragent", "Apache-HttpClient/Android");
params.setParameter("http.connection.stalecheck", Boolean.valueOf(false));
this.httpClient = new DefaultHttpClient(params);
this.httpClient.addRequestInterceptor(new GzipHttpRequestInterceptor());
this.httpClient.addResponseInterceptor(new GzipHttpResponseInterceptor());
this.httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
return this.httpClient;
}
示例4: setCredentialCharset
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
* Sets the charset to be used when encoding
* {@link org.apache.http.auth.Credentials}.
*
* @param charset The charset
*/
public static void setCredentialCharset(final HttpParams params, final String charset) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
params.setParameter(AuthPNames.CREDENTIAL_CHARSET, charset);
}
示例5: setMaxConnectionsPerRoute
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
* Sets lookup interface for maximum number of connections allowed per route.
*
* @param params HTTP parameters
* @param connPerRoute lookup interface for maximum number of connections allowed
* per route
*/
public static void setMaxConnectionsPerRoute(final HttpParams params,
final ConnPerRoute connPerRoute) {
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters must not be null.");
}
params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute);
}
示例6: getAsStringIfOk
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
public String getAsStringIfOk(String url) throws Exception {
HttpGet get = new HttpGet(url);
HttpParams params = new BasicHttpParams();
params.setParameter("http.protocol.handle-redirects",false);
get.setParams(params);
HttpResponse r = httpClient.execute(get);
String s = EntityUtils.toString(r.getEntity());
if (r.getStatusLine().getStatusCode() == 200) {
return s;
} else {
throw new RuntimeException(s);
}
}
示例7: copyParams
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
* Copies the locally defined parameters to the argument parameters.
* This method is called from {@link #clone()}.
*
* @param target the parameters to which to copy
* @since 4.2
*/
public void copyParams(HttpParams target) {
Iterator<Map.Entry<String, Object>> iter = this.parameters.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, Object> me = iter.next();
if (me.getKey() instanceof String)
target.setParameter(me.getKey(), me.getValue());
}
}
示例8: setProxy
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
* Sets the Proxy by it's hostname,port,username and password
*
* @param hostname the hostname (IP or DNS name)
* @param port the port number. -1 indicates the scheme default port.
* @param username the username
* @param password the password
*/
public void setProxy(String hostname, int port, String username, String password) {
httpClient.getCredentialsProvider().setCredentials(
new AuthScope(hostname, port),
new UsernamePasswordCredentials(username, password));
final HttpHost proxy = new HttpHost(hostname, port);
final HttpParams httpParams = this.httpClient.getParams();
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
示例9: setProxy
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
* Sets the Proxy by it's hostname,port,username and password
*
* @param hostname the hostname (IP or DNS name)
* @param port the port number. -1 indicates the scheme default port.
* @param username the username
* @param password the password
*/
public void setProxy(String hostname, int port, String username, String password) {
httpClient.getCredentialsProvider().setCredentials(
new AuthScope(hostname, port),
new UsernamePasswordCredentials(username, password));
final HttpHost proxy = new HttpHost(hostname, port);
final HttpParams httpParams = this.httpClient.getParams();
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
示例10: setCookiePolicy
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
public static void setCookiePolicy(final HttpParams params, final String cookiePolicy) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
}
示例11: setDefaultProxy
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
* Sets the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY}
* parameter value.
*
* @param params the parameters in which to set the value
* @param proxy the value to set, may be <code>null</code>.
* Note that {@link #NO_HOST} will be mapped to
* <code>null</code> by {@link #getDefaultProxy},
* to allow for explicit unsetting in hierarchies.
*/
public static void setDefaultProxy(HttpParams params,
HttpHost proxy) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
params.setParameter(DEFAULT_PROXY, proxy);
}
示例12: setProxy
import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
* Sets the Proxy by it's hostname,port,username and password
*
* @param hostname the hostname (IP or DNS name)
* @param port the port number. -1 indicates the scheme default port.
* @param username the username
* @param password the password
*/
public void setProxy(String hostname, int port, String username, String password) {
httpClient.getCredentialsProvider().setCredentials(new AuthScope(hostname, port), new UsernamePasswordCredentials(username, password));
final HttpHost proxy = new HttpHost(hostname, port);
final HttpParams httpParams = this.httpClient.getParams();
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}