當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。