HttpWebRequest 返回空文本

发布于 2024-10-18 07:44:15 字数 635 浏览 0 评论 0原文

当我尝试获取此 URL 的内容时 http://www.yellowpages.com.au/qld/gatton /a-12000029-listing.html

using System.Net;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link);
request.AllowAutoRedirect = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader objSR;
objSR = new StreamReader(resStream, System.Text.Encoding.GetEncoding("utf-8"));
string sResponse = objSR.ReadToEnd();

我没有收到服务器的任何响应。请帮我找出为什么会发生这种情况。

提前致谢!

When I try to fetch the content of this URL
http://www.yellowpages.com.au/qld/gatton/a-12000029-listing.html

using System.Net;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link);
request.AllowAutoRedirect = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader objSR;
objSR = new StreamReader(resStream, System.Text.Encoding.GetEncoding("utf-8"));
string sResponse = objSR.ReadToEnd();

I don't get any response from the server. Please help me find out why this happens.

Thanks in advance!

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

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

发布评论

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

评论(3

遥远的绿洲 2024-10-25 07:44:15

它很可能正在查看用户代理并拒绝向无法识别自身身份的客户端提供内容。尝试在请求对象上设置 UserAgent 属性。

It may well be looking at the user agent and refusing to serve content to a client that doesn't identify itself. Try setting the UserAgent property on your request object.

一曲爱恨情仇 2024-10-25 07:44:15

在我看来,该网站正在检查引用网址,如果指定了无效的引用网址,则可能会提供空内容。

尝试设置 request.Referer = "http://www.google.com";。对引荐来源网址进行实验,看看这是否会改变响应。我还会按照 Matthew 的建议尝试 UserAgent 属性。

Looks to me like that site is checking the referrer url and may be serving up empty content if an invalid referrer is specified.

Try setting request.Referer = "http://www.google.com";. Experiment with the referrer to see if that changes the response. I'd also try the UserAgent property as Matthew suggested.

梦里南柯 2024-10-25 07:44:15

我也遇到了同样的问题,原因是我之前将方法设置为 HEAD 并且在后来的修订中需要解析正文。

I had the same problem and the cause was that I previously had set the method to HEAD and in later revisions had the need to parse the body.

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