使用xml响应附加条件html文件输出

时间:2022-09-13 00:10:29

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" />

嘿家伙我有一个宁静的xml服务,客户端通过他们正在查看的当前版本的HTML。如果服务器上的版本与客户端相同,我只需用xml中的当前服务器版本进行响应。示例:

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

但是,如果服务器html版本大于当前客户端版本,我仍然会像上面的 那样吐出相同的响应。但问题是我的客户端应用程序需要单独的http请求下载html文件incase响应xml版本大于客户端版本

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

出于性能原因,我想减少这个http请求,我想知道最好的方法是什么。我应该简单地编码html以使其成为xml安全并附加xml响应 - 这是html的问题是FAT和编码使它更加胖

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

管理这个有更好的方法吗?请注意,我现在已经对xml和html的响应进行了gziping

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

我想知道如何做到这一点,牢记性能。 restful xml服务是通过asp.net 3.5和iis 7实现的

1 个解决方案

#1


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.

您是否考虑过使用HTTP标头?由于这里的主要数据确实是HTML,而ServerHTMLVersion是关于该HTML的一种“元数据”,它应该可以工作。

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.

就个人而言,当版本匹配时,我会对请求做出响应1)空白; 2)不匹配版本的HTML;然后,使用Pragma HTTP标头发送类似Pragma的内容:“ServerHTMLVersion = 2”。通过这样做,您可以轻松检查客户端和服务器版本是否不同,如果它们不同,只需获取完整响应即可。

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.

有些人会讨论从REST服务返回HTML的想法,但我个人认为这完全有效,并且是一种将元数据与实际用户数据分离的简洁方法。

-Jerod

#1


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.

您是否考虑过使用HTTP标头?由于这里的主要数据确实是HTML,而ServerHTMLVersion是关于该HTML的一种“元数据”,它应该可以工作。

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.

就个人而言,当版本匹配时,我会对请求做出响应1)空白; 2)不匹配版本的HTML;然后,使用Pragma HTTP标头发送类似Pragma的内容:“ServerHTMLVersion = 2”。通过这样做,您可以轻松检查客户端和服务器版本是否不同,如果它们不同,只需获取完整响应即可。

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.

有些人会讨论从REST服务返回HTML的想法,但我个人认为这完全有效,并且是一种将元数据与实际用户数据分离的简洁方法。

-Jerod