本文整理汇总了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);
}
示例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);
}
}