如何计算服务器发送给我的 100 个继续的数量?

发布于 2024-08-05 12:46:43 字数 235 浏览 5 评论 0原文

我正在使用 Apache Commons HttpClient 3.1,我发现 Sun 的 HttpURLConnection 会从流中删除 100 个继续。

因此,我似乎无法获得 100 Continue,因为它们显然被 Sun 的代码删除了。

我无法升级到 HttpClient 4.0,因为这需要对现有代码进行许多更改,因此解决方案必须是 3.1 或不冲突的版本。

有什么想法吗?

谢谢

I am using Apache Commons HttpClient 3.1, and I found that HttpURLConnection from Sun drops the 100 Continues from the stream.

So therefore I don't seem able to get the 100 Continue as they are apparently dropped by Sun's code.

I am unable to move forward to HttpClient 4.0 as that would require many changes to already existing code so the solution has to either be 3.1 or something that doesn't conflict.

Any ideas?

Thanks

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

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

发布评论

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

评论(2

橘亓 2024-08-12 12:46:43

我找到了解决方案!

覆盖 processStatusLine 并检查状态 100。

请记住,前 100 个是预期的(服务器告诉我可以继续 POST),在我的情况下,我可以安全地忽略该状态。这样我就可以获得服务器响应的所有信息。

public class Counting100PostMethod extends PostMethod {
Logger log = Logger.getLogger(Counting100PostMethod.class);
boolean first100 = true;

public Counting100PostMethod() {
    super();
}

public Counting100PostMethod(String s) {
    super(s);
}

@Override
protected void processStatusLine(HttpState httpState, HttpConnection httpConnection) {
    super.processStatusLine(httpState, httpConnection);
    int status = getStatusCode();
    if (status == 100) {
        if (first100) {
            first100 = false;
        } else {
            // can now increment counter
            log.debug("Increment counter");
        }
    }
}

I found the solution!

Over-ride processStatusLine and check for status of 100.

Remember that the first 100 is expected (server telling me I can continue with the POST), and in my case I can safely ignore that one. This way I get all the information that my server is responding with.

public class Counting100PostMethod extends PostMethod {
Logger log = Logger.getLogger(Counting100PostMethod.class);
boolean first100 = true;

public Counting100PostMethod() {
    super();
}

public Counting100PostMethod(String s) {
    super(s);
}

@Override
protected void processStatusLine(HttpState httpState, HttpConnection httpConnection) {
    super.processStatusLine(httpState, httpConnection);
    int status = getStatusCode();
    if (status == 100) {
        if (first100) {
            first100 = false;
        } else {
            // can now increment counter
            log.debug("Increment counter");
        }
    }
}
娇纵 2024-08-12 12:46:43

似乎这种行为是预期的,并被此问题拒绝:https://bugs。 java.com/bugdatabase/view_bug?bug_id=4396798

It seems like this behavior is expected and was rejected by this issue: https://bugs.java.com/bugdatabase/view_bug?bug_id=4396798.

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