HttpWebResponse in Thread throws Forbidden
I would like to call multiple times to a web resource, however I get forbidden when asking the webresponse.
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 = (H开发者_如何学编程ttpWebRequest) HttpWebRequest.Create("http://www.google.com");
WebResponse res = wr.GetResponse();
There's a default limit of 2 simultaneous requests to the same domain built into the framework. Just put this line of code into your code after you've created the HttpWebRequest object:
wr.ServicePoint.ConnectionLimit = 50;
Check out the docs: http://msdn.microsoft.com/en-us/library/kd5csyhf.aspx
精彩评论