Apache httpclient的execute方法调试

栏目: Java · 发布时间: 6年前

内容简介:因为工作需要,想研究一下execute执行的逻辑。在这一行调用execute:getHttpClient的实现:

因为工作需要,想研究一下execute执行的逻辑。

在这一行调用execute:

response = getHttpClient().execute(get);

getHttpClient的实现:

private HttpClient getHttpClient() {
        if (this.m_httpClient == null) {
            this.m_httpClient = HttpClientBuilder.create().build();
        }
        return this.m_httpClient;
    }

我在代码里声明的HttpClient只是一个接口,

Apache httpclient的execute方法调试

实现类是InternalHttpClient。

Apache httpclient的execute方法调试

首先根据传入的请求决定出目标-target host

Apache httpclient的execute方法调试

投递到RedirectExec执行。

Apache httpclient的execute方法调试

后者又投递到RetryExec执行。

Apache httpclient的execute方法调试

收到307重定向:

Apache httpclient的execute方法调试

redirectsEnabled标志位为true:

Apache httpclient的execute方法调试

再看当前的请求确实被redirect了吗?

Apache httpclient的execute方法调试

original url:

Apache httpclient的execute方法调试

我的后台服务器返回的307,落到了分支HttpStatus.SC_TEMPORARY_REDIRECT处:

Apache httpclient的execute方法调试

看来Apache的库认为只有HEAD和GET才能被redirect:

Apache httpclient的execute方法调试

重定向最大次数:50

Apache httpclient的execute方法调试

准备重试了:

Apache httpclient的execute方法调试

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

Apache httpclient的execute方法调试


以上所述就是小编给大家介绍的《Apache httpclient的execute方法调试》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Mastering Regular Expressions, Second Edition

Mastering Regular Expressions, Second Edition

Jeffrey E F Friedl / O'Reilly Media / 2002-07-15 / USD 39.95

Regular expressions are an extremely powerful tool for manipulating text and data. They have spread like wildfire in recent years, now offered as standard features in Perl, Java, VB.NET and C# (and an......一起来看看 《Mastering Regular Expressions, Second Edition》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具