使用 HttpWebRequest 下载
假设我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
request.GetResponse()
是同步的,这意味着在下载所有数据之前它不会返回。request.GetResponse 的文档
()
声明在以下情况下抛出WebException
:这意味着如果没有抛出异常,一切都会正常。
request.GetResponse()
is synchronous which means that it doesn't return until all data have been downloaded.The documentation of
request.GetResponse()
states thatWebException
is thrown if:Which means that everything went OK if no exception was thrown.