线程中的 HttpWebResponse 抛出 Forbidden
我想多次调用网络资源,但是在询问网络响应时被禁止。
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();
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 = (HttpWebRequest) HttpWebRequest.Create("http://www.google.com");
WebResponse res = wr.GetResponse();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对同一域的默认限制是 2 个同时请求
进入框架。只需将这行代码放入您的代码中即可
您已创建 HttpWebRequest 对象:
查看文档:http://msdn。 microsoft.com/en-us/library/kd5csyhf.aspx
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:
Check out the docs: http://msdn.microsoft.com/en-us/library/kd5csyhf.aspx