使用 HttpWebRequest 下载

发布于 2024-12-20 12:55:53 字数 622 浏览 0 评论 0原文

假设我使用 HttpWebRequest 调用用 python 编写的 Web 服务,并且该服务返回一个 XML 文件。假设下载数据需要 10 秒。

 HttpWebResponse response = (HttpWebResponse)req.GetResponse();

 if(allDate100%Transfered)
 MsgBox.show("u can now CUT your cable. All data is there!!!");

是否有任何财产可以检查所有物品是否已转移?

因为我想继续,例如将接收到的数据读入字符串中,但前提是所有数据均已成功下载。

Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
String xml = reader.ReadToEnd();

我是否从网络服务收到任何消息或标志,告诉我所有数据确实存在并且我不再需要连接?

编辑:问题仍然存在。我得到了不同的答案,而且它们相互矛盾

Lets say that I use HttpWebRequest to call a web-service written in python and that service returns a XML file. Lets assume that it takes 10 seconds to download the data.

 HttpWebResponse response = (HttpWebResponse)req.GetResponse();

 if(allDate100%Transfered)
 MsgBox.show("u can now CUT your cable. All data is there!!!");

Are there any property to check if everything have been transferred?

Because I want to proceed and for example read the received data into a string, but only when all data have been downloaded successfully.

Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
String xml = reader.ReadToEnd();

Do I get any message or sign from the webservice, which tells me that all data is really there and I do not need the connection anymore?

Edit: The problem is stil there. I get different answers and they contradict each other.

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

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

发布评论

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

评论(1

橘虞初梦 2024-12-27 12:55:53

request.GetResponse() 是同步的,这意味着在下载所有数据之前它不会返回。

request.GetResponse 的文档() 声明在以下情况下抛出 WebException

  • 先前调用了 Abort。
  • 请求的超时期限已过。
  • 处理请求时发生错误。

这意味着如果没有抛出异常,一切都会正常。

request.GetResponse() is synchronous which means that it doesn't return until all data have been downloaded.

The documentation of request.GetResponse() states that WebException is thrown if:

  • Abort was previously called.
  • The time-out period for the request expired.
  • An error occurred while processing the request.

Which means that everything went OK if no exception was thrown.

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