HttpWebRequest的关于第三次尝试超时,只有两个连接允许HTTP 1.1 [英] HttpWebRequest timing out on third try, only two connections allowed HTTP 1.1

查看:416
本文介绍了HttpWebRequest的关于第三次尝试超时,只有两个连接允许HTTP 1.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for (int i = 0; i < endurance / 10; i++) {
    log.Info("mining now : " + endurance / 10 + " - " + i);
    HttpWebRequest mineRequest = WebRequestUtil.CreateHttpWebRequest(Properties.Settings.Default.PAGE_URL + Properties.Settings.Default.MINING_URL);

    string source = SourceParser.GetSource(mineRequest); // GETTING TIMED OUT HERE
    string variable = GetHiddenVariableNumber(source);

    Mine(variable);
}

我的方法的getSource:

My GetSource method:

public static string GetSource(WebRequest request) {
    using (WebResponse response = request.GetResponse()) {
        using (Stream stream = response.GetResponseStream()) {
            using (StreamReader reader = new StreamReader(stream)) {
                return reader.ReadToEnd();
            }
        }
    }
}

日志:

2013-03-03 02:10:56,101 [13] INFO  Bot.Game.Mining mining now : 10 - 0
2013-03-03 02:10:57,053 [13] INFO  Bot.Game.Mining mining now : 10 - 1
2013-03-03 02:10:58,155 [13] INFO  Bot.Game.Mining mining now : 10 - 2 // ends here

有什么建议?我很多读到它和通常的问题是,不处理 WebResponse类的对象,但我这样做

Any suggestions? I read alot about it and usual problem was that not of disposing of Stream or WebResponse object, but I am doing that.

推荐答案

我想这可能是的ServicePoint的问题。它提供了连接管理HTTP连接。

I think this may be matter of ServicePoint. Which provides connection management for HTTP connections.

用的ServicePoint对象允许的并发连接的默认最大数目为2。所以,如果你需要增加它,你可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit.aspx"相对=nofollow> ServicePointManager.DefaultConnectionLimit 财产。

The default maximum number of concurrent connections allowed by a ServicePoint object is 2. So if you need to increase it you can use ServicePointManager.DefaultConnectionLimit property.

这篇关于HttpWebRequest的关于第三次尝试超时,只有两个连接允许HTTP 1.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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