HttpURLConnection的setConnectTimeout()没有任何影响 [英] HttpURLConnection setConnectTimeout() has no effect

查看:583
本文介绍了HttpURLConnection的setConnectTimeout()没有任何影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我连接到一个简单的RSS源使用HttpURLConnection类。它完美。我想超时添加到连接,因为我不希望我的应用程序挂在连接不良或任何事件。这是code我用的setConnectTimeout方法没有任何任何影响。

I'm connecting to a simple RSS feed using HTTPUrlConnection. It works perfectly. I'd like to add a timeout to the connection since I don't want my app hanging in the event of a bad connection or whatever. This is the code I use and the setConnectTimeout method doesn't have any effect whatsoever.

        HttpURLConnection http = (HttpURLConnection) mURL.openConnection();
        http.setConnectTimeout(15000); //timeout after 15 seconds
...

如果它可以帮助我开发的机器人。

If it helps I'm developing on android.

推荐答案

您应该尝试设置读取超时以及(http.setReadTimeout <$ C C $>())。通常情况下,Web服务器会很乐意接受您的连接,但它可能是缓慢的实际响应请求。

You should try to set the read timeout as well (http.setReadTimeout()). Oftentimes, a web server will happily accept your connection, but it might be slow in actually responding to the request.

这篇关于HttpURLConnection的setConnectTimeout()没有任何影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆