.net downloadstring(url) 突然返回 503 错误

发布于 2024-11-17 14:05:14 字数 376 浏览 6 评论 0原文

我有一个简单的函数来抓取一个网页,该网页突然从特定页面的以下代码中收到 503 错误:

try
{
  WebClient client = new WebClient();
  client.Proxy = null;
  string webhtml = client.DownloadString(strURL);
  client.Dispose();
  return (webhtml);
}

当我在 IE 或 FF 中输入该 url 时,该 url 有效,但当此代码运行时它返回错误。其他网址工作正常。我猜想来自 .net 的 http 请求与来自任一浏览器的 http 请求有所不同。有没有办法更好地模拟基于浏览器的http请求?

谢谢。

I have a simple function to scrape a web page that is suddenly getting a 503 error from the following code for a specific page:

try
{
  WebClient client = new WebClient();
  client.Proxy = null;
  string webhtml = client.DownloadString(strURL);
  client.Dispose();
  return (webhtml);
}

The url works when I enter it in IE or FF but it's returning an error when this code runs. Other urls work fine. I'm guessing there is something different about the http request from .net than from either of the browsers. Is there any way to better emulate a browser-based http request?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新人笑 2024-11-24 14:05:14

从此站点找到了我正在寻找的 http 标头。非常有用。

http://www.ericgiguere.com/tools/http-header-viewer.html

Found the http headers I was looking for from this site. Very useful.

http://www.ericgiguere.com/tools/http-header-viewer.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文