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


Java OkAuthenticator.authenticateProxy方法代码示例

本文整理汇总了Java中com.squareup.okhttp.OkAuthenticator.authenticateProxy方法的典型用法代码示例。如果您正苦于以下问题:Java OkAuthenticator.authenticateProxy方法的具体用法?Java OkAuthenticator.authenticateProxy怎么用?Java OkAuthenticator.authenticateProxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.okhttp.OkAuthenticator的用法示例。


在下文中一共展示了OkAuthenticator.authenticateProxy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processAuthHeader

import com.squareup.okhttp.OkAuthenticator; //导入方法依赖的package包/类
/**
 * React to a failed authorization response by looking up new credentials.
 * Returns a request for a subsequent attempt, or null if no further attempts
 * should be made.
 */
public static Request processAuthHeader(
    OkAuthenticator authenticator, Response response, Proxy proxy) throws IOException {
  String responseField;
  String requestField;
  if (response.code() == HTTP_UNAUTHORIZED) {
    responseField = "WWW-Authenticate";
    requestField = "Authorization";
  } else if (response.code() == HTTP_PROXY_AUTH) {
    responseField = "Proxy-Authenticate";
    requestField = "Proxy-Authorization";
  } else {
    throw new IllegalArgumentException(); // TODO: ProtocolException?
  }
  List<Challenge> challenges = parseChallenges(response.headers(), responseField);
  if (challenges.isEmpty()) return null; // Could not find a challenge so end the request cycle.

  Request request = response.request();
  Credential credential = response.code() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, request.url(), challenges)
      : authenticator.authenticate(proxy, request.url(), challenges);
  if (credential == null) return null; // Couldn't satisfy the challenge so end the request cycle.

  // Add authorization credentials, bypassing the already-connected check.
  return request.newBuilder().header(requestField, credential.getHeaderValue()).build();
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:31,代码来源:HttpAuthenticator.java

示例2: processAuthHeader

import com.squareup.okhttp.OkAuthenticator; //导入方法依赖的package包/类
/**
 * React to a failed authorization response by looking up new credentials.
 *
 * @return true if credentials have been added to successorRequestHeaders
 *         and another request should be attempted.
 */
public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode,
    RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url)
    throws IOException {
  String responseField;
  String requestField;
  if (responseCode == HTTP_UNAUTHORIZED) {
    responseField = "WWW-Authenticate";
    requestField = "Authorization";
  } else if (responseCode == HTTP_PROXY_AUTH) {
    responseField = "Proxy-Authenticate";
    requestField = "Proxy-Authorization";
  } else {
    throw new IllegalArgumentException(); // TODO: ProtocolException?
  }
  List<Challenge> challenges = parseChallenges(responseHeaders, responseField);
  if (challenges.isEmpty()) {
    return false; // Could not find a challenge so end the request cycle.
  }
  Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, url, challenges)
      : authenticator.authenticate(proxy, url, challenges);
  if (credential == null) {
    return false; // Could not satisfy the challenge so end the request cycle.
  }
  // Add authorization credentials, bypassing the already-connected check.
  successorRequestHeaders.set(requestField, credential.getHeaderValue());
  return true;
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:35,代码来源:HttpAuthenticator.java


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