服务器发送事件通过post方法传递参数

编程入门 行业动态 更新时间:2024-10-26 02:34:31
本文介绍了服务器发送事件通过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方法传递参数

本文发布于:2023-10-12 00:15:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   事件   服务器   方法   post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!