当前位置: 首页>>代码示例>>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;未经允许,请勿转载。