Can Server Sent Events (SSE) with EventSource pass parameter by POST
While you cannot use the EventSource
API to do so, there is no technical reason why a server cannot implement for a POST request. The trick is getting the client to send the request. For instance This answer discusses sse.js as a drop in replacement for EventSource
.
No, the SSE standard does not allow POST.
(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
(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.)
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. 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.