• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DefaultHttpClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getSardine

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
protected Sardine getSardine(){
	if (sardine_==null){

		// transform into http://myserver/myfolder
		connexionURL=connexionURL.replaceAll(" ", "%20");
		connexionURL = getURLWithoutSlash(connexionURL);
		// webdavServer is a string like "http://myserver"
		//webdavServer = connexionURL.substring(0, connexionURL.lastIndexOf("/"));
		// webdavRootFolder is a string like "/myfolder/"




		AbstractHttpClient client = wrapClient(new DefaultHttpClient());
		sardine_ = new SardineImpl(client, this.getParamValues().get(loginKey),
				this.getParamValues().get(pwdKey));
	}
	return sardine_;
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:20,代码来源:FileProvider7.java


示例2: wrapClient

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
public static AbstractHttpClient wrapClient(HttpClient base) {
	try {
		SSLContext ctx = SSLContext.getInstance("TLS");
		X509TrustManager tm = new X509AlwaysTrust();

		ctx.init(null, new TrustManager[] { tm }, null);
		SSLSocketFactory ssf = new ch.boye.httpclientandroidlib.conn.ssl.SSLSocketFactory(
				ctx);
		ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		ClientConnectionManager ccm = base.getConnectionManager();
		SchemeRegistry sr = ccm.getSchemeRegistry();
		sr.register(new Scheme("https", ssf, 443));
		return new DefaultHttpClient(ccm, base.getParams());
	} catch (Exception ex) {
		ex.printStackTrace();
		return null;
	}
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:19,代码来源:FileProvider7.java


示例3: addHeaders

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public void addHeaders(HttpRequestBase request, DefaultHttpClient client) {
  super.addHeaders(request, client);

  // The basics.
  final Locale locale = Locale.getDefault();
  request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, Locales.getLanguageTag(locale));
  request.addHeader(HttpHeaders.ACCEPT, ACCEPT_HEADER);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:10,代码来源:FxAccountClient20.java


示例4: addHeaders

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public void addHeaders(HttpRequestBase request, DefaultHttpClient client) {
  // Clients can use their delegate interface to specify X-If-Unmodified-Since.
  String ifUnmodifiedSince = this.request.delegate.ifUnmodifiedSince();
  if (ifUnmodifiedSince != null) {
    Logger.debug(LOG_TAG, "Making request with X-If-Unmodified-Since = " + ifUnmodifiedSince);
    request.setHeader("x-if-unmodified-since", ifUnmodifiedSince);
  }
  if (request.getMethod().equalsIgnoreCase("DELETE")) {
    request.addHeader("x-confirm-delete", "1");
  }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:13,代码来源:SyncStorageRequest.java


示例5: getAuthHeader

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) throws GeneralSecurityException {
  long timestamp = System.currentTimeMillis() / 1000;
  String nonce = Base64.encodeBase64String(Utils.generateRandomBytes(NONCE_LENGTH_IN_BYTES));
  String extra = "";

  try {
    return getAuthHeader(request, context, client, timestamp, nonce, extra);
  } catch (InvalidKeyException | NoSuchAlgorithmException | UnsupportedEncodingException e) {
    // We lie a little and make every exception a GeneralSecurityException.
    throw new GeneralSecurityException(e);
  }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:14,代码来源:HMACAuthHeaderProvider.java


示例6: getAuthHeader

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) throws GeneralSecurityException {
  long timestamp = getTimestampSeconds();
  String nonce = Base64.encodeBase64String(Utils.generateRandomBytes(NONCE_LENGTH_IN_BYTES));
  String extra = "";

  try {
    return getAuthHeader(request, context, client, timestamp, nonce, extra, this.includePayloadHash);
  } catch (Exception e) {
    // We lie a little and make every exception a GeneralSecurityException.
    throw new GeneralSecurityException(e);
  }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:14,代码来源:HawkAuthHeaderProvider.java


示例7: prepareClient

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
/**
 * Invoke this after delegate and request have been set.
 * @throws NoSuchAlgorithmException
 * @throws KeyManagementException
 */
protected void prepareClient() throws KeyManagementException, NoSuchAlgorithmException, GeneralSecurityException {
  context = new BasicHttpContext();

  // We could reuse these client instances, except that we mess around
  // with their parameters… so we'd need a pool of some kind.
  client = new DefaultHttpClient(getConnectionManager());

  // TODO: Eventually we should use Apache HttpAsyncClient. It's not out of alpha yet.
  // Until then, we synchronously make the request, then invoke our delegate's callback.
  AuthHeaderProvider authHeaderProvider = delegate.getAuthHeaderProvider();
  if (authHeaderProvider != null) {
    Header authHeader = authHeaderProvider.getAuthHeader(request, context, client);
    if (authHeader != null) {
      request.addHeader(authHeader);
      Logger.debug(LOG_TAG, "Added auth header.");
    }
  }

  addAuthCacheToContext(request, context);

  HttpParams params = client.getParams();
  HttpConnectionParams.setConnectionTimeout(params, delegate.connectionTimeout());
  HttpConnectionParams.setSoTimeout(params, delegate.socketTimeout());
  HttpConnectionParams.setStaleCheckingEnabled(params, false);
  HttpProtocolParams.setContentCharset(params, charset);
  HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
  final String userAgent = delegate.getUserAgent();
  if (userAgent != null) {
    HttpProtocolParams.setUserAgent(params, userAgent);
  }
  delegate.addHeaders(request, client);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:38,代码来源:BaseResource.java


示例8: addHeaders

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public void addHeaders(HttpRequestBase request, DefaultHttpClient client) {
  String host = request.getURI().getHost();
  request.setHeader(new BasicHeader(HttpHeaders.HOST, host));
  if (clientState != null) {
    request.setHeader(new BasicHeader(HEADER_CLIENT_STATE, clientState));
  }
  if (conditionsAccepted) {
    request.addHeader(HEADER_CONDITIONS_ACCEPTED, "1");
  }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:12,代码来源:TokenServerClient.java


示例9: createDefaultClient

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
/**
 * Creates an AbstractHttpClient with all of the defaults.
 */
protected AbstractHttpClient createDefaultClient(ProxySelector selector) {
	SchemeRegistry schemeRegistry = this.createDefaultSchemeRegistry();
	ClientConnectionManager cm = this
			.createDefaultConnectionManager(schemeRegistry);
	HttpParams params = this.createDefaultHttpParams();
	AbstractHttpClient client = new DefaultHttpClient(cm, params);
	client.setRoutePlanner(this.createDefaultRoutePlanner(schemeRegistry,
			selector));
	return client;
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:14,代码来源:SardineImpl.java


示例10: getSardine

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
protected Sardine getSardine(){
	if (sardine_==null){

		connexionURL = getURLWithoutSlash(connexionURL);

		AbstractHttpClient client = wrapClient(new DefaultHttpClient());
		sardine_ = new SardineImpl(client, this.getParamValues().get(loginKey),
				this.getParamValues().get(pwdKey));
	}
	return sardine_;
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:12,代码来源:FileProvider5.java


示例11: addHeaders

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public void addHeaders(HttpRequestBase request, DefaultHttpClient client) {
  if (ifModifiedSince != -1L) {
    // TODO: format?
    request.addHeader("If-Modified-Since", "" + ifModifiedSince);
  }
  super.addHeaders(request, client);
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:9,代码来源:ReadingListClient.java


示例12: addHeaders

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public void addHeaders(HttpRequestBase request, DefaultHttpClient client) {
  super.addHeaders(request, client);

  // The basics.
  final Locale locale = Locale.getDefault();
  request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, Utils.getLanguageTag(locale));
  request.addHeader(HttpHeaders.ACCEPT, ACCEPT_HEADER);
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:10,代码来源:FxAccountAbstractClient.java


示例13: addHeaders

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public void addHeaders(HttpRequestBase request, DefaultHttpClient client) {
  super.addHeaders(request, client);
  request.setHeader(HTTP.CONTENT_TYPE, COMPRESSED_CONTENT_TYPE);
  if (this.obsoleteDocumentIDs != null && this.obsoleteDocumentIDs.size() > 0) {
    request.addHeader(HEADER_OBSOLETE_DOCUMENT, Utils.toCommaSeparatedString(this.obsoleteDocumentIDs));
  }
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:9,代码来源:BagheeraClient.java


示例14: getAuthHeader

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) throws GeneralSecurityException {
  if (this.token.isEmpty()) {
    return null;
  }
  return new BasicHeader("Authorization", token);
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:8,代码来源:DeviceManager.java


示例15: getAuthHeader

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
/**
 * Return a Header object representing an Authentication header for HTTP
 * Basic.
 */
@Override
public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) {
  Credentials creds = new UsernamePasswordCredentials(credentials);

  // This must be UTF-8 to generate the same Basic Auth headers as desktop for non-ASCII passwords.
  return BasicScheme.authenticate(creds, "UTF-8", false);
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:12,代码来源:BasicAuthHeaderProvider.java


示例16: init

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
private void init() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    registry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    ClientConnectionManager cm = new PoolingClientConnectionManager(registry);
    mClient = new DefaultHttpClient(cm);
}
 
开发者ID:youtaya,项目名称:crabapple,代码行数:8,代码来源:SilkHttpBase.java


示例17: addHeaders

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public void addHeaders(HttpRequestBase request, DefaultHttpClient client) {
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:4,代码来源:BaseResourceDelegate.java


示例18: getAuthHeader

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
@Override
public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) {
  return new BasicHeader("Authorization", header);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:5,代码来源:AbstractBearerTokenAuthHeaderProvider.java


示例19: delete

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
public void delete(final String guid, final ReadingListDeleteDelegate delegate, final long ifUnmodifiedSince) {
  final BaseResource r = getRelativeArticleResource(guid);

  // If If-Unmodified-Since is provided, and the record has been modified,
  // we'll receive a 412 Precondition Failed.
  // If the record is missing or already deleted, a 404 will be returned.
  // Otherwise, the response will be the deleted record.
  r.delegate = new ReadingListResourceDelegate<ReadingListRecordResponse>(r, auth, ReadingListRecordResponse.FACTORY) {
    @Override
    public void addHeaders(HttpRequestBase request, DefaultHttpClient client) {
      if (ifUnmodifiedSince != -1) {
        request.addHeader("If-Unmodified-Since", "" + ifUnmodifiedSince);
      }
      super.addHeaders(request, client);
    }

    @Override
    void onFailure(MozResponse response) {
      switch (response.getStatusCode()) {
      case 412:
        delegate.onPreconditionFailed(guid, response);
        return;
      }
      delegate.onFailure(response);
    }

    @Override
    void onSuccess(ReadingListRecordResponse response) {
      final ReadingListRecord record;
      try {
        record = response.getRecord();
      } catch (Exception e) {
        delegate.onFailure(e);
        return;
      }

      delegate.onSuccess(response, record);
    }

    @Override
    void onFailure(Exception ex) {
      delegate.onFailure(ex);
    }

    @Override
    void onNonSuccess(ReadingListRecordResponse response) {
      if (response.getStatusCode() == 404) {
        // Already deleted!
        delegate.onRecordMissingOrDeleted(guid, response);
      }
    }
  };

  if (ReadingListConstants.DEBUG) {
    Logger.debug(LOG_TAG, "Deleting " + r.getURIString());
  }
  r.delete();
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:59,代码来源:ReadingListClient.java


示例20: authenticateAccount

import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; //导入依赖的package包/类
/**
 * Makes an authentication request to the server and passes appropriate response back to callback.
 * @param callbackDelegate
 *        Delegate to deal with HTTP response.
 * @param authRequestUrl
 * @param authHeader
 * @throws URISyntaxException
 */
// Made public for testing.
public void authenticateAccount(final AuthenticateAccountStageDelegate callbackDelegate, final String authRequestUrl, final String authHeader) throws URISyntaxException {
  final BaseResource httpResource = new BaseResource(authRequestUrl);
  httpResource.delegate = new BaseResourceDelegate(httpResource) {
    @Override
    public String getUserAgent() {
      return SyncConstants.USER_AGENT;
    }

    @Override
    public void addHeaders(HttpRequestBase request, DefaultHttpClient client) {
      // Make reference to request, to abort if necessary.
      httpRequest = request;
      client.log.enableDebug(true);
      // Host header is not set for some reason, so do it explicitly.
      try {
        URI authServerUri = new URI(authRequestUrl);
        request.setHeader(new BasicHeader("Host", authServerUri.getHost()));
      } catch (URISyntaxException e) {
        Logger.error(LOG_TAG, "Malformed uri, will be caught elsewhere.", e);
      }
      request.setHeader(new BasicHeader("Authorization", authHeader));
    }

    @Override
    public void handleHttpResponse(HttpResponse response) {
      int statusCode = response.getStatusLine().getStatusCode();
      try {
        switch (statusCode) {
        case 200:
          callbackDelegate.handleSuccess(true);
          break;
        case 401:
          callbackDelegate.handleSuccess(false);
          break;
        default:
          callbackDelegate.handleFailure(response);
        }
      } finally {
        BaseResource.consumeEntity(response.getEntity());
        Logger.info(LOG_TAG, "Released entity.");
      }
    }

    @Override
    public void handleHttpProtocolException(ClientProtocolException e) {
      Logger.error(LOG_TAG, "Client protocol error.", e);
      callbackDelegate.handleError(e);
    }

    @Override
    public void handleHttpIOException(IOException e) {
      Logger.error(LOG_TAG, "I/O exception.");
      callbackDelegate.handleError(e);
    }

    @Override
    public void handleTransportException(GeneralSecurityException e) {
      Logger.error(LOG_TAG, "Transport exception.");
      callbackDelegate.handleError(e);
    }
  };

  AccountAuthenticator.runOnThread(new Runnable() {
    @Override
    public void run() {
      httpResource.get();
    }
  });
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:79,代码来源:AuthenticateAccountStage.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NineGridView类代码示例发布时间:2022-05-23
下一篇:
Java BulkConnection类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap