The parameter "Sent server events" is passed by the post method

I am using Html5 Server Sent Events. On the server side is the Java Servlet. I want the json array data to go to the server.

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

If the size of the array is small, the server side may receive a request. But if the size of the array is large. (maybe more than a thousand characters), the server cannot receive the request. Is it possible to use the POST method in new EventSource(...) to transfer a json array to the server, which can avoid request length limits?

+7
json server-sent-events
source share
1 answer

No, the SSE standard does not allow POST.

(For some technical reason, as far as I could tell, I think that designers have never seen use cases: it's not just big data, but if you want to do basic authentication of the scheme there are security reasons not to enter a password in the GET data .)

XMLHttpRequest (i.e. AJAX) allows POST, so one option is to revert to the old long-poll / comet methods. (My book, Data Push Apps with HTML5 SSE, details how to do this.)

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

The PS standard does not explicitly say that POST cannot be used. But, unlike XMLHttpRequest , there is no parameter to specify the http method used and do not specify the data that you want to publish.

+16
source share

All Articles