有没有比 WebClient 或 HttpWebRequest 更好的方法从 URL 检索原始 XML? [。网]
我正在开发一个地理编码应用程序,我将地址放入 URL 中并检索 XML。我需要该项目的完整 XML 响应。是否有任何其他类可以比使用 WebClient 或 HttpWebRequest 更快地从网站下载 XML?是否可以使用 XMLReader 来获取完整的 XML,而无需进行字符串操作,这会更快和/或更高效吗?
I am working on a Geocoding app where I put the address in the URL and retrieve the XML. I need the complete XML response for this project. Is there any other class for downloading the XML from a website that may be faster than using WebClient or HttpWebRequest? Can the XMLReader be used to get the full XML without string manipulation and would that be faster and/or more efficient?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,您可以使用
XmlReader.Create(uri)
- 但我认为这很可能在幕后使用HttpWebRequest
。我怀疑是否存在完全独立的 HTTP 客户端实现。先下载然后解析的一个优点是,如果文档有任何问题,如果您先将其存储在内存中,则可以更轻松地记录整个内容。此外,使用单独的
HttpWebRequest
(或WebClient
)可以让您更好地控制代理、处理重定向、身份验证等。这可能与您的用例相关,也可能不相关。课程。您是否尝试过以您能想到的最简单的方式进行编码,然后发现存在性能瓶颈?我预计主要问题出在网络中,而不是本地客户端处理中。
Well you can use
XmlReader.Create(uri)
- but that's likely to useHttpWebRequest
under the hood, I should think. I doubt that there's a completely separate HTTP client implementation. One advantage of downloading first and then parsing is that if there's anything wrong with the document, it's easier to log the whole thing if you've got it in memory first.Also, using a separate
HttpWebRequest
(orWebClient
) gives you more control over proxies, handling redirection, authentication etc. That may or may not be relevant for your use case, of course.Have you tried coding this in the simplest way you can think of and then found there to be a performance bottleneck? I'd expect the main issue to be in the network, not in local client processing.
XDocument.Load 方法 也可以做到这一点......但是我真的怀疑它会比任何其他替代方案更快。不过,这非常方便! :)
The XDocument.Load method can also do the trick ... but I really doubt it will be faster than any of the other alternatives. It's very convenient, though! :)