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


Java HttpStatus.SC_MOVED_TEMPORARILY属性代码示例

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


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

示例1: isRedirected

public boolean isRedirected(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    int statusCode = response.getStatusLine().getStatusCode();
    String method = request.getRequestLine().getMethod();
    Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        return isRedirectable(method) && locationHeader != null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return isRedirectable(method);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:DefaultRedirectStrategy.java

示例2: isRedirectRequested

public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        HttpRequest request = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
        String method = request.getRequestLine().getMethod();
        return method.equalsIgnoreCase(HttpGet.METHOD_NAME)
            || method.equalsIgnoreCase(HttpHead.METHOD_NAME);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:DefaultRedirectHandler.java

示例3: isRedirectRequested

@Override
public boolean isRedirectRequested(
        final HttpResponse response,
        final HttpContext context) {
    if (!enableRedirects) {
        return false;
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    int statusCode = response.getStatusLine().getStatusCode();
    switch (statusCode) {
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
            return true;
        default:
            return false;
    } //end of switch
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:21,代码来源:MyRedirectHandler.java

示例4: execute

/**
 * 执行http请求方法
 *
 * @param httpClient
 * @param request
 * @return
 */
public static String execute(CloseableHttpClient httpClient, HttpRequestBase request) {
    String res = null;
    try {
        CloseableHttpResponse response = httpClient.execute(request, CookieContext.createHttpClientContext());
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) {
            String location = response.getFirstHeader("Location").getValue();
            return get(location);
        }
        res = IOUtils.getStringFromInputStream(response);
    } catch (IOException e) {
        logger.error(e.getMessage());
    } finally {
        try {
            httpClient.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    return res;
}
 
开发者ID:1991wangliang,项目名称:lorne_core,代码行数:27,代码来源:HttpUtils.java

示例5: callWebProxy

public void callWebProxy(String url) {
    String resultCode = "";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);

        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            HttpEntity entity = response.getEntity();
            resultCode = ResponseCode.CALLRESPONSEERROR;
            if (entity != null) {
                String responseString = EntityUtils.toString(entity);
                if (responseString.contains("Spark Jobs") && responseString.contains("Stages")
                        && responseString.contains("Storage") && responseString.contains("Environment")
                        && responseString.contains("Executors")) {
                    resultCode = ResponseCode.CALLSUCCESS;
                }
            }
        } else if (statusCode == HttpStatus.SC_MOVED_TEMPORARILY
                || statusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
            resultCode = ResponseCode.CALLFORBIDDEN;
        } else {
            resultCode = ResponseCode.OTHER_RESPONSE + String.valueOf(statusCode);
        }
    } catch (Exception e) {
        LOG.warn("WebProxyCall exception " + e.getMessage());
        resultCode = ResponseCode.CALLEXCEPTION;
    } finally {
        httpclient.close();
    }
    LOG.info("WebProxyCall result " + resultCode);
    if (!resultCode.equals(ResponseCode.CALLSUCCESS)) {
        System.exit(1);
    }
}
 
开发者ID:aliyun,项目名称:aliyun-cupid-sdk,代码行数:36,代码来源:WebProxyCall.java


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