java 看了一个框架源码不知原因

发布于 2022-09-12 13:44:23 字数 1238 浏览 28 评论 0

public class CustomRedirectStrategy extends LaxRedirectStrategy {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
        URI uri = getLocationURI(request, response, context);
        String method = request.getRequestLine().getMethod();
        if ("post".equalsIgnoreCase(method)) {
            try {
                HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) request;
                httpRequestWrapper.setURI(uri);
                httpRequestWrapper.removeHeaders("Content-Length");
                return httpRequestWrapper;
            } catch (Exception e) {
                logger.error("强转为HttpRequestWrapper出错");
            }
            return new HttpPost(uri);
        } else {
            return new HttpGet(uri);
        }
    }

源码地址:

https://github.com/code4craft/webmagic/blob/be892b80bf6682cd063d30ac25a79be0c079a901/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/CustomRedirectStrategy.java

现在的http 协议请求都不需要头 httpRequestWrapper.removeHeaders("Content-Length");?????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百合的盛世恋 2022-09-19 13:44:23

image
这个要看协议的具体设置了,有些是不需要content-length的,策略不同,我也只是知道大概,你可以找这2个参数,具体搜索一下。

第七度阳光i 2022-09-19 13:44:23

它这是要重定向过去了,重定向拿这个请求头没有啥用吧,具体得看下RFC文档是怎么解释的

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文