當前位置: 首頁>>代碼示例>>Java>>正文


Java OkAuthenticator類代碼示例

本文整理匯總了Java中com.squareup.okhttp.OkAuthenticator的典型用法代碼示例。如果您正苦於以下問題:Java OkAuthenticator類的具體用法?Java OkAuthenticator怎麽用?Java OkAuthenticator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OkAuthenticator類屬於com.squareup.okhttp包,在下文中一共展示了OkAuthenticator類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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:goodev,項目名稱:android-discourse,代碼行數:31,代碼來源:HttpAuthenticator.java

示例2: 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

示例3: 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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。