为什么我会收到错误“底层连接已关闭” 当获取图像时?
我正在使用一些代码来获取给定 URL 的图像,它对我尝试过的所有 URL 都有效,除了一个:
http://title.mximg.com/img/logo/bizrealty.com.gif
对于此 URL,我收到“底层连接已关闭:接收时发生意外错误” ”。
但是,如果您使用浏览器打开该 URL,它会完美加载。
显然该错误消息的含义是:
“底层连接已关闭: 发生意外错误 接收。”
--当客户端发送完整的请求并获得 TCP 时看到 来自服务器的 ACK-FIN 或 RST 关闭 连接,无响应 来自服务器。
但我不知道这意味着什么:-(
代码很简单:
Dim req As System.Net.HttpWebRequest = DirectCast(WebRequest.Create(ImageURL), HttpWebRequest)
req.Method = "GET"
Dim resp As Net.HttpWebResponse = DirectCast(req.GetResponse(), Net.HttpWebResponse)
更新:将 KeepAlive 设置为 false 没有帮助。另外,这不是超时问题,我很快就收到错误。
知道可能是什么发生什么事了?
谢谢!
I'm using a little code to grab an image given its URL, and it's working for me for all URLs I tried except one:
http://title.mximg.com/img/logo/bizrealty.com.gif
For this URL, I'm getting "The underlying connection was closed: An unexpected error occurred on a receive."
However, if you open that URL with a browser, it loads perfectly.
Apparently that error message means:
"The underlying connection was closed:
An unexpected error occurred on a
receive."
--Seen when the client had sent the request in its entirety and got a TCP
ACK-FIN or RST from server to close
the connection, without a response
from server.
But I have no idea what that means :-(
The code is simply:
Dim req As System.Net.HttpWebRequest = DirectCast(WebRequest.Create(ImageURL), HttpWebRequest)
req.Method = "GET"
Dim resp As Net.HttpWebResponse = DirectCast(req.GetResponse(), Net.HttpWebResponse)
UPDATE: Setting KeepAlive to false doesn't help it. Also, it's not a timeout issue, I'm getting the error quite fast.
Any idea what could be going on?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试更新您的请求设置,例如 UserAgent 或接受。 他们可能会动态提供图像并拒绝看起来不像正常流量的请求。
I'd try updating your request settings like UserAgent or Accept. It's possible they're serving images dynamically and reject requests that don't look like normal traffic.