附加条件 html 文件输出和 xml 响应
嘿伙计们,我有一个宁静的 xml 服务,客户端传递他们正在查看的 html 的当前版本。 如果服务器上的版本与客户端相同,我只需以 xml 形式响应当前服务器版本。 例如:
但是,如果服务器 html 版本大于当前客户端版本,我仍然会输出与上面相同的响应,例如
。 但问题是我的客户端应用程序需要执行单独的 http 请求来下载 html 文件,以防出于性能原因响应 xml 版本大于客户端版本
,我想减少此 http 请求,并且我想知道什么是最好的方法做这个。 我是否应该简单地对 html 进行编码以使其 xml 安全,并附加 xml 响应 - 问题是 html 是 FAT 且编码使其更胖,
还是
有更好的方法来管理它? 请注意,我已经对 xml 和 html 的响应进行了 gzip 压缩,现在
我想知道如何在考虑到性能的情况下执行此操作。 Restful xml服务是通过asp.net 3.5和iis 7实现的
hey guys i have a restful xml service where client passes current version of html they are viewing. if the version on the server is the same as the client, i just respond with the current server version in xml. example: <Response ServerHTMLVersion="1" />
however if server html version is greater than current client version, i still spit out the same response like above like <Response ServerHTMLVersion="2" />
. but problem being my client application needs to do a seperate http request to download the html file incase response xml version is greater than clients version
for performance reasons, i wanted to cut down this http request and i wanted to know what is the best way to do this. should i simply encode the html to make it xml safe and append that with xml response - problem with this being html is FAT and encoding makes it even fatter
OR
is there a better way of managing this? note that i am already gziping my response for both, xml as well as html right now
i wanted to know the way to do this keeping performance in mind. the restful xml service is implemented via asp.net 3.5 and iis 7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过使用 HTTP 标头? 由于这里的主要数据实际上是 HTML,而 ServerHTMLVersion 是有关该 html 的一种“元数据”,因此它应该可以工作。
就我个人而言,我会对请求做出响应:1)版本匹配时为空,2)版本不匹配时为 HTML; 然后,使用 Pragma HTTP 标头发送类似 Pragma:“ServerHTMLVersion=2”的内容。 通过这样做,您可以轻松检查客户端和服务器版本是否不同,如果不同,则获取完整响应。
有些人会争论从 REST 服务返回 HTML 的想法,但我个人认为这是完全有效的,并且是一种将元数据与实际用户数据分离的好干净的方法。
-杰罗德
Have you thought about using HTTP headers? Since really the primary data here is the HTML, and the ServerHTMLVersion is a sort of "meta data" about that html, it should work.
Personally, I'd make the response to the request 1) blank when the versions match and 2) the HTML for non-matching versions; then, use the Pragma HTTP header to send something like Pragma: "ServerHTMLVersion=2". By doing this, you can easily check if the client and server versions differ, and just grab the full response if they're different.
Some people would debate the idea of returning HTML from a REST service, but I personally would consider this totally valid, and an nice clean way of separating your meta data from the actual user data.
-Jerod