服务器发送事件通过post方法传递参数 [英] Server Sent Events pass parameter by post method

查看:128
本文介绍了服务器发送事件通过post方法传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Html5服务器发送事件.服务器端是Java Servlet. 我有一个要传递到服务器的json数组数据.

I'm using Html5 Server Sent Events. The server side is Java Servlet. I have a json array data wants to pass to server.

var source = new EventSource("../GetPointVal?id=100&jsondata=" + JSON.stringify(data));

如果数组大小较小,则服务器端可以获取查询字符串. 但是,如果数组大小很大. (可能超过数千个字符),服务器无法获取查询字符串. 是否可以在new EventSource(...)中使用POST方法将json数组传递到可以避免查询字符串长度限制的服务器?

If the array size is small , the server side can get the querystring. But if the array size is big. (maybe over thousands of characters), the server can't get the querystring. Is it possible to use POST method in new EventSource(...) to to pass the json array to server that can avoid the querystring length limitation?

推荐答案

否,SSE标准不允许POST.

No, the SSE standard does not allow POST.

(出于任何技术原因,据我所知-我认为只是设计人员从未见过用例:它不仅是大数据,而且还想进行自定义身份验证方案,出于安全原因,请勿将密码放在GET数据中.)

(For no technical reason, as far as I've been able to tell - I think it was just that the designers never saw the use cases: it is not just large data, but if you want to do a custom authentication scheme there are security reasons not to put the password in GET data.)

XMLHttpRequest(即AJAX)确实允许POST,因此一种选择是返回到较早的长轮询/彗星方法. (我的书带有HTML5 SSE的数据推送应用详细介绍了如何执行这个.)

XMLHttpRequest (i.e. AJAX) does allow POST, so one option is to go back to the older long-poll/comet methods. (My book, Data Push Apps with HTML5 SSE goes into quite some detail about how to do this.)

另一种方法是预先将所有数据存储在POST中,然后将其存储在HttpSession中,然后调用SSE进程,该进程可以利用该会话数据. (SSE确实支持cookie,因此JSESSIONID cookie应该可以正常工作.)

Another approach is to POST all the data in beforehand, and store it in an HttpSession, and then call the SSE process, which can make use of that session data. (SSE does support cookies, so the JSESSIONID cookie should work fine.)

P.S. 标准并未明确指出无法使用POST.但是,与XMLHttpRequest不同,没有参数指定要使用的http方法,也没有方法指定要发布的数据.

P.S. The standard doesn't explicitly say POST cannot be used. But, unlike XMLHttpRequest, there is no parameter to specify the http method to use, and no way to specify the data you want to post.

这篇关于服务器发送事件通过post方法传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆