当前位置: 首页>>代码示例>>Java>>正文


Java ClientPNames类代码示例

本文整理汇总了Java中org.apache.http.client.params.ClientPNames的典型用法代码示例。如果您正苦于以下问题:Java ClientPNames类的具体用法?Java ClientPNames怎么用?Java ClientPNames使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClientPNames类属于org.apache.http.client.params包,在下文中一共展示了ClientPNames类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setHeaders

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
private synchronized void setHeaders(Collection<BasicHeader> headers) {
	if (headers != null && headers.size() != 0){
		
		@SuppressWarnings("unchecked")
		Collection<BasicHeader> preHeaders = (Collection<BasicHeader>) mHttpClient.getParams().getParameter(ClientPNames.DEFAULT_HEADERS);
		if (preHeaders == null){
			preHeaders = new ArrayList<BasicHeader>();
		}
		for(BasicHeader bh:headers){
			for(BasicHeader bh1:preHeaders){
				if(bh.getName().equals(bh1.getName())){
					preHeaders.remove(bh1);
					break;
				}
			}
			if (bh.getValue() != null){
				preHeaders.add(bh);
			}
		}
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:22,代码来源:HttpHelper.java

示例2: process

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }

    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        return;
    }

    // Add default headers
    @SuppressWarnings("unchecked")
    Collection<Header> defHeaders = (Collection<Header>) request.getParams().getParameter(
            ClientPNames.DEFAULT_HEADERS);

    if (defHeaders != null) {
        for (Header defHeader : defHeaders) {
            request.addHeader(defHeader);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:RequestDefaultHeaders.java

示例3: downloadHTTPfile_post

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
private byte[] downloadHTTPfile_post(String formToDownloadLocation, List<NameValuePair> params) throws IOException, NullPointerException, URISyntaxException {
  	BasicHttpContext localContext = new BasicHttpContext();
 
      LOG.info("Mimic WebDriver cookie state: " + this.mimicWebDriverCookieState);
      if (this.mimicWebDriverCookieState) {
          localContext.setAttribute(ClientContext.COOKIE_STORE, mimicCookieState(this.driver.manage().getCookies()));
      }
 
      HttpPost httppost = new HttpPost(formToDownloadLocation);
      HttpParams httpRequestParameters = httppost.getParams();
      httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects);
      httppost.setParams(httpRequestParameters);
      httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
      
      LOG.info("Sending POST request for: " + httppost.getURI());
      @SuppressWarnings("resource")
HttpResponse response = new DefaultHttpClient().execute(httppost, localContext);
      this.httpStatusOfLastDownloadAttempt = response.getStatusLine().getStatusCode();
      LOG.info("HTTP GET request status: " + this.httpStatusOfLastDownloadAttempt);
 
      byte[] file = IOUtils.toByteArray(response.getEntity().getContent());
      response.getEntity().getContent().close();
      return file;
  }
 
开发者ID:GovernIB,项目名称:helium,代码行数:25,代码来源:FileDownloader.java

示例4: getHTTPStatusCode

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
/**
    * Perform an HTTP Status check and return the response code
    *
    * @return
    * @throws IOException
    */
   @SuppressWarnings("resource")
public int getHTTPStatusCode() throws IOException {

       HttpClient client = new DefaultHttpClient();
       BasicHttpContext localContext = new BasicHttpContext();

       LOG.info("Mimic WebDriver cookie state: " + this.mimicWebDriverCookieState);
       if (this.mimicWebDriverCookieState) {
           localContext.setAttribute(ClientContext.COOKIE_STORE, mimicCookieState(this.driver.manage().getCookies()));
       }
       HttpRequestBase requestMethod = this.httpRequestMethod.getRequestMethod();
       requestMethod.setURI(this.linkToCheck);
       HttpParams httpRequestParameters = requestMethod.getParams();
       httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects);
       requestMethod.setParams(httpRequestParameters);

       LOG.info("Sending " + requestMethod.getMethod() + " request for: " + requestMethod.getURI());
       HttpResponse response = client.execute(requestMethod, localContext);
       LOG.info("HTTP " + requestMethod.getMethod() + " request status: " + response.getStatusLine().getStatusCode());

       return response.getStatusLine().getStatusCode();
   }
 
开发者ID:GovernIB,项目名称:helium,代码行数:29,代码来源:URLStatusChecker.java

示例5: getHttpParams

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
/**
 * 此处解释下MaxtTotal和DefaultMaxPerRoute的区别:
 * 1、MaxtTotal是整个池子的大小;
 * 2、DefaultMaxPerRoute是根据连接到的主机对MaxTotal的一个细分;比如:
 * MaxtTotal=400 DefaultMaxPerRoute=200
 * 而我只连接到http://sishuok.com时,到这个主机的并发最多只有200;而不是400;
 * 而我连接到http://sishuok.com 和 http://qq.com时,到每个主机的并发最多只有200;即加起来是400(但不能超过400);所以起作用的设置是DefaultMaxPerRoute。
 */
public HttpParams getHttpParams() {
    HttpParams params = new BasicHttpParams();
    // 设置连接超时时间
    Integer CONNECTION_TIMEOUT = 2 * 1000; // 设置请求超时2秒钟 根据业务调整
    Integer SO_TIMEOUT = 2 * 1000; // 设置等待数据超时时间2秒钟 根据业务调整
    // 定义了当从ClientConnectionManager中检索ManagedClientConnection实例时使用的毫秒级的超时时间
    // 这个参数期望得到一个java.lang.Long类型的值。如果这个参数没有被设置,默认等于CONNECTION_TIMEOUT,因此一定要设置
    Long CONN_MANAGER_TIMEOUT = 500L; // 该值就是连接不够用的时候等待超时时间,一定要设置,而且不能太大 ()

    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT);
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT);
    params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, CONN_MANAGER_TIMEOUT);
    // 在提交请求之前 测试连接是否可用
    params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true);
    return params;
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:25,代码来源:GetClient.java

示例6: process

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");

    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        return;
    }

    // Add default headers
    @SuppressWarnings("unchecked")
    Collection<? extends Header> defHeaders = (Collection<? extends Header>)
        request.getParams().getParameter(ClientPNames.DEFAULT_HEADERS);
    if (defHeaders == null) {
        defHeaders = this.defaultHeaders;
    }

    if (defHeaders != null) {
        for (final Header defHeader : defHeaders) {
            request.addHeader(defHeader);
        }
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:24,代码来源:RequestDefaultHeadersHC4.java

示例7: createHttpClient

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
private void createHttpClient(NaviPoolConfig poolConfig, ServerUrlUtil.ServerUrl server) {
    if (params == null) {
        // httpClient.setParams(params)HttpParams
        httpClient = new DefaultHttpClient(cm);
        httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, poolConfig.getSocketTimeout());
        httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, poolConfig.getConnectTimeout());
    } else {
        httpClient = new DefaultHttpClient(cm, params);
        if (poolConfig instanceof NaviHttpPoolConfig) {
            httpClient.setHttpRequestRetryHandler(
                new NaviHttpRequestRetryHandler(((NaviHttpPoolConfig) poolConfig).getRetryTimes(), false)
            );
        }
    }
    // 配置数据源
    httpClient.getParams().setParameter(ClientPNames.DEFAULT_HOST, new HttpHost(server.getHost(), server.getPort()));
}
 
开发者ID:sunguangran,项目名称:navi,代码行数:18,代码来源:NaviHttpClientDriver.java

示例8: process

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");

    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        return;
    }

    // Add default headers
    @SuppressWarnings("unchecked")
    Collection<? extends Header> defHeaders = (Collection<? extends Header>)
        request.getParams().getParameter(ClientPNames.DEFAULT_HEADERS);
    if (defHeaders == null) {
        defHeaders = this.defaultHeaders;
    }

    if (defHeaders != null) {
        for (final Header defHeader : defHeaders) {
            request.addHeader(defHeader);
        }
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:25,代码来源:RequestDefaultHeaders.java

示例9: authenticateAtLocalhost

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
private void authenticateAtLocalhost() throws Exception {
    HttpClient httpClient = new DefaultHttpClient();
    httpClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);

    HttpPost httpPost = new HttpPost("http://localhost:8888/_ah/login");
    httpPost.setHeader("Content-Type","application/x-www-form-urlencoded");
    String email = URLEncoder.encode("[email protected]", "UTF-8");
    String redirectUrl = URLEncoder.encode("http://localhost:8888", "UTF-8");
    httpPost.setEntity(new StringEntity("email=" + email + "&continue=" + redirectUrl + "&isAdmin=on"));
    HttpResponse response = httpClient.execute(httpPost);

    authenticationCookie = response.getFirstHeader("Set-Cookie").getValue();
    httpClient.getConnectionManager().shutdown();

    baseUrl="http://localhost:8888/rest";       
}
 
开发者ID:dvorka,项目名称:mindraider,代码行数:17,代码来源:MindForgerClient.java

示例10: testSetParams

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
@Test
public void testSetParams() {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(HttpClientUtil.PROP_ALLOW_COMPRESSION, true);
  params.set(HttpClientUtil.PROP_BASIC_AUTH_PASS, "pass");
  params.set(HttpClientUtil.PROP_BASIC_AUTH_USER, "user");
  params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 12345);
  params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, true);
  params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 22345);
  params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32345);
  params.set(HttpClientUtil.PROP_SO_TIMEOUT, 42345);
  params.set(HttpClientUtil.PROP_USE_RETRY, false);
  DefaultHttpClient client = (DefaultHttpClient) HttpClientUtil.createClient(params);
  assertEquals(12345, HttpConnectionParams.getConnectionTimeout(client.getParams()));
  assertEquals(PoolingClientConnectionManager.class, client.getConnectionManager().getClass());
  assertEquals(22345, ((PoolingClientConnectionManager)client.getConnectionManager()).getMaxTotal());
  assertEquals(32345, ((PoolingClientConnectionManager)client.getConnectionManager()).getDefaultMaxPerRoute());
  assertEquals(42345, HttpConnectionParams.getSoTimeout(client.getParams()));
  assertEquals(HttpClientUtil.NO_RETRY, client.getHttpRequestRetryHandler());
  assertEquals("pass", client.getCredentialsProvider().getCredentials(new AuthScope("127.0.0.1", 1234)).getPassword());
  assertEquals("user", client.getCredentialsProvider().getCredentials(new AuthScope("127.0.0.1", 1234)).getUserPrincipal().getName());
  assertEquals(true, client.getParams().getParameter(ClientPNames.HANDLE_REDIRECTS));
  client.getConnectionManager().shutdown();
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:HttpClientUtilTest.java

示例11: init

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
@Override
public void init() throws ServletException {
  String doLogStr = getConfigParam(P_LOG);
  if (doLogStr != null) {
    this.doLog = Boolean.parseBoolean(doLogStr);
  }

  String doForwardIPString = getConfigParam(P_FORWARDEDFOR);
  if (doForwardIPString != null) {
    this.doForwardIP = Boolean.parseBoolean(doForwardIPString);
  }

  initTarget();//sets target*

  HttpParams hcParams = new BasicHttpParams();
  hcParams.setParameter(ClientPNames.COOKIE_POLICY,
      CookiePolicy.IGNORE_COOKIES);
  readConfigParam(hcParams, ClientPNames.HANDLE_REDIRECTS, Boolean.class);
  proxyClient = createHttpClient(hcParams);
}
 
开发者ID:hopshadoop,项目名称:hopsworks,代码行数:21,代码来源:ProxyServlet.java

示例12: prepareForBrowser

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
public void prepareForBrowser() {
    // Clear cookies, let the browser handle them
    httpClient.setCookieStore(new BlankCookieStore());
    httpClient.getCookieSpecs().register("easy", new CookieSpecFactory() {
        @Override
        public CookieSpec newInstance(final HttpParams params) {
            return new BrowserCompatSpec() {
                @Override
                public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException {
                    // easy!
                }
            };
        }
    });
    httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, "easy");
    decompress = false;
    setFollowRedirects(false);
}
 
开发者ID:epam,项目名称:Wilma,代码行数:19,代码来源:BrowserMobHttpClient.java

示例13: init

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
@Override
public void init() throws ServletException {
    String doLogStr = getConfigParam(P_LOG);
    if (doLogStr != null) {
        this.doLog = Boolean.parseBoolean(doLogStr);
    }

    String doForwardIPString = getConfigParam(P_FORWARDEDFOR);
    if (doForwardIPString != null) {
        this.doForwardIP = Boolean.parseBoolean(doForwardIPString);
    }

    initTarget();// sets target*

    HttpParams hcParams = new BasicHttpParams();
    hcParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
    readConfigParam(hcParams, ClientPNames.HANDLE_REDIRECTS, Boolean.class);
    proxyClient = createHttpClient(hcParams);
}
 
开发者ID:sercxtyf,项目名称:onboard,代码行数:20,代码来源:ApiProxyServlet.java

示例14: getDefaultHttpClient

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
/** 
 * 获取DefaultHttpClient对象 
 *  
 * @param charset 
 *            字符编码 
 * @return DefaultHttpClient对象 
 */  
private static DefaultHttpClient getDefaultHttpClient(final String charset) {  
    DefaultHttpClient httpclient = new DefaultHttpClient();  
    // 模拟浏览器,解决一些服务器程序只允许浏览器访问的问题  
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,  
            USER_AGENT);  
    httpclient.getParams().setParameter(  
            CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);  
    httpclient.getParams().setParameter(  
            CoreProtocolPNames.HTTP_CONTENT_CHARSET,  
            charset == null ? CHARSET_ENCODING : charset);  
      
    // 浏览器兼容性  
    httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY,  
            CookiePolicy.BROWSER_COMPATIBILITY);  
    // 定义重试策略  
    httpclient.setHttpRequestRetryHandler(requestRetryHandler);  
      
    return httpclient;  
}
 
开发者ID:hoozheng,项目名称:AndroidRobot,代码行数:27,代码来源:HttpClientUtil.java

示例15: init

import org.apache.http.client.params.ClientPNames; //导入依赖的package包/类
public void init() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory
            .getSocketFactory(), 80));
    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, 10);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params,
            schemeRegistry);
    httpClient = new DefaultHttpClient(cm, params);
    // 重试
    // httpClient.setHttpRequestRetryHandler(new
    // DefaultHttpRequestRetryHandler(3, false));
    // 超时设置
    // httpClient.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT,
    // 10000);
    // httpClient.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT,
    // 10000);
    httpClient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,
            true);

    threadNum = 10;
    execService = Executors.newFixedThreadPool(threadNum);
    destroy = false;
}
 
开发者ID:cobola,项目名称:smth3k,代码行数:26,代码来源:SmthCrawler.java


注:本文中的org.apache.http.client.params.ClientPNames类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。