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


Java HttpURLConnection.getHeaderFieldInt方法代碼示例

本文整理匯總了Java中java.net.HttpURLConnection.getHeaderFieldInt方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpURLConnection.getHeaderFieldInt方法的具體用法?Java HttpURLConnection.getHeaderFieldInt怎麽用?Java HttpURLConnection.getHeaderFieldInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.HttpURLConnection的用法示例。


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

示例1: parseUnavailableHeaders

import java.net.HttpURLConnection; //導入方法依賴的package包/類
private void parseUnavailableHeaders(HttpURLConnection conn) {
    long retryAfter = conn.getHeaderFieldInt("Retry-After", -1);
    if (retryAfter < 0) {
        retryAfter = 0;
    } else {
        if (retryAfter < Constants.MIN_RETRY_AFTER) {
            retryAfter = Constants.MIN_RETRY_AFTER;
        } else if (retryAfter > Constants.MAX_RETRY_AFTER) {
            retryAfter = Constants.MAX_RETRY_AFTER;
        }
        retryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
    }

    mInfoDelta.mRetryAfter = (int) (retryAfter * SECOND_IN_MILLIS);
}
 
開發者ID:redleaf2002,項目名稱:downloadmanager,代碼行數:16,代碼來源:DownloadThread.java

示例2: throwExceptionForErrorResponse

import java.net.HttpURLConnection; //導入方法依賴的package包/類
/**
 * Throws the appropriate ClarifaiException for the response code from an HttpURLConnection,
 * populating the message from the response payload.
 */
static void throwExceptionForErrorResponse(HttpURLConnection conn, BaseResponse response)
    throws IOException, ClarifaiException {
  String errorMessage = "";
  if (response.statusCode != null) {
    errorMessage += response.statusCode;
  }
  if (response.statusMsg != null) {
    errorMessage += " " + response.statusMsg;
  }
  if (response.results != null && response.results.isJsonPrimitive()) {
    errorMessage += " " + response.results.getAsString();
  }
  if (errorMessage.length() == 0) {
    errorMessage = conn.getResponseMessage();
  }

  int code = conn.getResponseCode();
  if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
    throw new ClarifaiNotAuthorizedException(errorMessage);
  } else if (code == 429) {  // Too Many Requests
    int waitSeconds = conn.getHeaderFieldInt("X-Throttle-Wait-Seconds", 10);
    throw new ClarifaiThrottledException(errorMessage, waitSeconds);
  } else if (code >= 400 && code < 500) {
    throw new ClarifaiBadRequestException(errorMessage);
  } else if (code >= 500 && code < 600) {
    throw new ClarifaiException(errorMessage);
  } else {
    throw new ClarifaiException("Unexpected HTTP status code (" + code + "): " + errorMessage);
  }
}
 
開發者ID:Kitt3120,項目名稱:ViperBot,代碼行數:35,代碼來源:ResponseUtil.java


注:本文中的java.net.HttpURLConnection.getHeaderFieldInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。