Thread中的HttpWebResponse抛出Forbidden

时间:2011-03-17 09:57:13

标签: c# asp.net multithreading

我想多次拨打网络资源,但在询问网络回复时我被禁止。

protected void Page_Load(object sender, EventArgs e)
    {


        Thread[] tt = new Thread[10];
        for (int i = 0; i < 10; i++)
        {            
            Thread t = new Thread(doJob);
            tt[i] = t;
            t.Start();
        }

        foreach (Thread t in tt)
        {
            t.Join();
        }
        Response.Write("TOTAL" + howmanyDone);
    }

    private void doJob()
    {        
        HttpWebRequest wr = (HttpWebRequest) HttpWebRequest.Create("http://www.google.com");        
        WebResponse res = wr.GetResponse();

1 个答案:

答案 0 :(得分:1)

对于构建的同一域,默认限制为2个并发请求 进入框架。只需将这行代码放入代码中 你已经创建了HttpWebRequest对象:

wr.ServicePoint.ConnectionLimit = 50;

查看文档:{​​{3}}