{"id":38715,"date":"2025-05-21T08:51:04","date_gmt":"2025-05-21T00:51:04","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38715.html"},"modified":"2025-05-21T08:51:04","modified_gmt":"2025-05-21T00:51:04","slug":"%e6%b5%8f%e8%a7%88%e5%99%a8%e4%b8%8e%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84%e8%bd%bb%e9%87%8f%e9%95%bf%e8%bf%9e%e6%8e%a5-text-event-stream-%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90%e4%b8%8e","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38715.html","title":{"rendered":"\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u7684\u8f7b\u91cf\u957f\u8fde\u63a5\u2014\u2014text\/event-stream \u6df1\u5ea6\u89e3\u6790\u4e0e\u5b9e\u8df5"},"content":{"rendered":"<p>\u4f34\u968f\u5b9e\u65f6 Web \u7684\u5174\u8d77&#xff0c;\u5f00\u53d1\u8005\u8d8a\u6765\u8d8a\u9700\u8981\u4e00\u79cd\u5f00\u9500\u5c0f\u3001\u90e8\u7f72\u7b80\u5355\u3001\u53c8\u4e0d\u5931\u53ef\u9760\u6027\u7684\u63a8\u9001\u673a\u5236\u3002text\/event-stream \u6b63\u662f\u5728\u8fd9\u79cd\u9700\u6c42\u80cc\u666f\u4e0b\u5e94\u8fd0\u800c\u751f\u7684 MIME \u7c7b\u578b&#xff1a;\u6d4f\u89c8\u5668\u901a\u8fc7 EventSource \u63a5\u53e3\u53d1\u8d77\u4e00\u6b21\u666e\u901a HTTP \u8bf7\u6c42&#xff0c;\u670d\u52a1\u5668\u6309 text\/event-stream \u89c4\u8303\u6301\u7eed\u5c06\u4e8b\u4ef6\u5757\u5199\u56de&#xff0c;\u8fde\u63a5\u5f97\u4ee5\u5e38\u9a7b&#xff0c;\u6570\u636e\u5373\u53ef\u6e90\u6e90\u4e0d\u65ad\u5730\u5355\u5411\u6d41\u5165\u9875\u9762\u3002\u5b83\u501f\u52a9\u73b0\u6210\u7684 HTTP \u57fa\u7840\u8bbe\u65bd\u907f\u5f00\u4e86\u590d\u6742\u63e1\u624b&#xff0c;\u5374\u4f9d\u65e7\u80fd\u63d0\u4f9b\u7c7b\u4f3c WebSocket \u7684\u5b9e\u65f6\u4f53\u9a8c\u3002\u4e0b\u6587\u4ece\u534f\u8bae\u7ec6\u8282\u3001\u6d4f\u89c8\u5668\u5b9e\u73b0\u3001\u6700\u4f73\u5b9e\u8df5\u5230\u6027\u80fd\u5b89\u5168\u5168\u666f\u5c55\u5f00&#xff0c;\u914d\u5408\u5b9e\u9645\u6848\u4f8b\u4e0e\u5bf9\u6bd4\u5206\u6790&#xff0c;\u529b\u6c42\u4e3a\u4f60\u5448\u73b0\u4e00\u4e2a\u53ef\u843d\u5730\u3001\u53ef\u6269\u5c55\u3001\u53ef\u7ef4\u62a4\u7684 text\/event-stream \u4e16\u754c\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521005103-682d23770d71f.png\" alt=\"\" \/><\/p>\n<h3>\u80cc\u666f\u4e0e\u6982\u5ff5<\/h3>\n<p>HTML Standard \u5c06 Server-Sent Events&#xff08;\u7b80\u79f0 SSE&#xff09;\u5b9a\u4e49\u4e3a\u6d4f\u89c8\u5668\u7aef EventSource \u63a5\u53e3\u4e0e\u670d\u52a1\u5668\u7aef\u4e8b\u4ef6\u6d41\u683c\u5f0f\u7684\u7ec4\u5408&#xff1b;\u4e8b\u4ef6\u6d41\u5185\u5bb9\u7684\u5b98\u65b9 MIME \u7c7b\u578b\u5373 text\/event-stream&#xff0c;\u5e76\u8981\u6c42 UTF-8 \u7f16\u7801(HTML Standard, HTML Standard)\u3002\u5f53\u6d4f\u89c8\u5668\u68c0\u6d4b\u5230\u54cd\u5e94\u5934 Content-Type: text\/event-stream&#xff0c;\u4fbf\u4f1a\u628a\u63a5\u6536\u7684\u6570\u636e\u6309\u7167\u884c\u5206\u9694\u89c4\u5219\u89e3\u6790\u6210\u79bb\u6563\u4e8b\u4ef6&#xff0c;\u800c\u65e0\u9700\u4e8c\u6b21\u89e3\u6790 JSON \u6216\u81ea\u5b9a\u4e49\u534f\u8bae\u3002\u56e0\u6b64&#xff0c;text\/event-stream \u5e76\u975e\u4e00\u95e8\u65b0\u534f\u8bae&#xff0c;\u800c\u662f\u5bf9\u73b0\u6709 HTTP \u7684\u6700\u5c0f\u589e\u91cf\u6269\u5c55\u3002<\/p>\n<p>\u4e0e\u4f20\u7edf\u7684 Ajax \u8f6e\u8be2\u76f8\u6bd4&#xff0c;SSE \u53ea\u521b\u5efa\u4e00\u6b21 TCP \u8fde\u63a5\u5e76\u91cd\u7528\u8be5\u8fde\u63a5\u8f93\u9001\u6240\u6709\u66f4\u65b0&#xff0c;\u663e\u8457\u964d\u4f4e\u4e86\u63e1\u624b\u5f00\u9500\u548c\u5ef6\u8fdf(MDN Web Docs, MDN Web Docs)\u3002\u4e0e WebSocket \u7684\u53cc\u5411\u4fe1\u9053\u4e0d\u540c&#xff0c;SSE \u4ec5\u652f\u6301\u670d\u52a1\u5668\u5411\u5ba2\u6237\u7aef\u5355\u5411\u63a8\u9001&#xff0c;\u4f46\u5b83\u7684\u90e8\u7f72\u5bf9\u53cd\u5411\u4ee3\u7406\u3001\u9632\u706b\u5899\u3001CDN \u66f4\u53cb\u597d&#xff0c;\u56e0\u4e3a\u62a5\u6587\u4fdd\u6301\u7eaf\u6587\u672c HTTP \u683c\u5f0f(Ably Realtime, Ably Realtime)\u3002\u8fd9\u4f7f\u5f97 text\/event-stream \u5728\u9700\u8981\u6d4f\u89c8\u5668\u9891\u7e41\u63a5\u6536\u800c\u5f88\u5c11\u53d1\u9001\u6570\u636e\u7684\u573a\u666f\u2014\u2014\u4f8b\u5982\u76d1\u63a7\u9762\u677f\u3001\u4ef7\u683c\u884c\u60c5\u3001\u65e5\u5fd7\u6d41\u2014\u2014\u5c55\u73b0\u51fa\u6781\u9ad8\u7684\u6027\u4ef7\u6bd4\u3002<\/p>\n<h3>\u4e8b\u4ef6\u6d41\u683c\u5f0f\u4e0e\u5de5\u4f5c\u673a\u5236<\/h3>\n<h4>\u8bf7\u6c42\u9636\u6bb5<\/h4>\n<p>\u6d4f\u89c8\u5668\u901a\u8fc7 new EventSource(&#039;\/stream&#039;) \u521b\u5efa\u8fde\u63a5\u65f6&#xff0c;\u4f1a\u81ea\u52a8\u5728\u8bf7\u6c42\u5934\u52a0\u5165 Accept: text\/event-stream&#xff0c;\u8868\u660e\u53ea\u63a5\u53d7\u7b26\u5408\u4e8b\u4ef6\u6d41\u89c4\u8303\u7684\u54cd\u5e94(MDN Web Docs)\u3002\u670d\u52a1\u5668\u82e5\u652f\u6301 SSE&#xff0c;\u5e94\u8fd4\u56de\u72b6\u6001\u7801 200 \u6216 206&#xff0c;\u5e76\u5199\u5165 Content-Type: text\/event-stream \u4ee5\u53ca\u53ef\u9009\u7684 Cache-Control: no-cache&#xff0c;\u968f\u540e\u7acb\u5373 flush \u8f93\u51fa\u7f13\u51b2\u533a&#xff0c;\u8ba9\u5ba2\u6237\u7aef\u5c3d\u65e9\u8fdb\u5165\u5c31\u7eea\u6001\u3002<\/p>\n<h4>\u6570\u636e\u5757\u8bed\u6cd5<\/h4>\n<p>\u4e00\u6761\u4e8b\u4ef6\u6d88\u606f\u7531\u82e5\u5e72\u884c\u952e\u503c\u5bf9\u7ec4\u6210&#xff0c;\u6bcf\u884c\u683c\u5f0f\u4e3a field:value\\\\n&#xff0c;\u6d88\u606f\u672b\u5c3e\u4ee5\u989d\u5916\u7a7a\u884c\u7ed3\u675f\u3002\u5e38\u7528\u5b57\u6bb5\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\n<p>data: \u4e8b\u4ef6\u8f7d\u8377&#xff0c;\u591a\u884c data: \u4f1a\u88ab\u5408\u5e76\u5e76\u4ee5 \\\\n \u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>event: \u81ea\u5b9a\u4e49\u4e8b\u4ef6\u540d&#xff0c;\u5bf9\u5e94 EventSource \u76d1\u542c\u5668\u7684\u7c7b\u578b\u3002<\/p>\n<\/li>\n<li>\n<p>id: \u9012\u589e\u552f\u4e00\u6807\u8bc6&#xff0c;\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u5728\u540e\u7eed\u8bf7\u6c42\u7684 Last-Event-ID \u5934\u643a\u5e26\u8be5\u503c&#xff0c;\u4fbf\u4e8e\u65ad\u7ebf\u7eed\u4f20\u3002<\/p>\n<\/li>\n<li>\n<p>retry: \u670d\u52a1\u5668\u5efa\u8bae\u7684\u91cd\u8fde\u95f4\u9694&#xff08;\u6beb\u79d2&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u89c4\u8303\u8981\u6c42\u884c\u5206\u9694\u53ef\u4ee5\u662f CRLF\u3001LF \u6216 CR&#xff0c;\u5e76\u660e\u786e\u7a7a\u884c\u624d\u662f\u6d88\u606f\u7ed3\u675f\u6807\u5fd7(HTML Standard)\u3002<\/p>\n<h4>\u4fdd\u6d3b\u4e0e\u81ea\u52a8\u91cd\u8fde<\/h4>\n<p>\u82e5\u8fde\u63a5\u610f\u5916\u65ad\u5f00&#xff0c;\u6d4f\u89c8\u5668\u4f1a\u6309\u7167\u4e0a\u6b21\u6210\u529f\u63a5\u6536\u7684 retry \u5b57\u6bb5\u6216\u9ed8\u8ba4 3 \u79d2\u7b56\u7565\u91cd\u8fde&#xff0c;\u5e76\u9644\u5e26 Last-Event-ID \u4ee5\u5b9e\u73b0\u81f3\u5c11\u4e00\u6b21\u9001\u8fbe\u8bed\u4e49(Stack Overflow)\u3002\u670d\u52a1\u5668\u53ef\u901a\u8fc7\u53d1\u9001 :comment\\\\n\\\\n \u4fdd\u6d3b\u5e27\u5411\u4ee3\u7406\u58f0\u660e\u8fde\u63a5\u6d3b\u8dc3\u72b6\u6001&#xff1b;\u8be5\u884c\u4ee5\u5192\u53f7\u5f00\u5934&#xff0c;\u4e0d\u4ea7\u751f\u4efb\u4f55\u4e8b\u4ef6&#xff0c;\u4ec5\u7528\u4e8e\u907f\u514d\u95f2\u7f6e\u8fde\u63a5\u88ab\u4e2d\u95f4\u4ef6\u5173\u95ed(Stack Overflow)\u3002<\/p>\n<h3>\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\u4e0e\u7f51\u7edc\u8bbe\u65bd<\/h3>\n<p>\u81ea Chrome 6\u3001Firefox 6\u3001Safari 5.1\u3001Edge 79 \u8d77&#xff0c;\u4e3b\u6d41\u6d4f\u89c8\u5668\u5747\u5df2\u5bf9 EventSource \u63d0\u4f9b\u5b8c\u6574\u5b9e\u73b0&#xff0c;\u552f\u72ec IE \u7cfb\u5217\u4ece\u672a\u652f\u6301&#xff0c;\u8be5\u5dee\u8ddd\u53ef\u901a\u8fc7 polyfill \u6216\u56de\u9000\u5230\u957f\u8f6e\u8be2\u7b56\u7565\u5f25\u8865(Can I Use, LambdaTest)\u3002\u7531\u4e8e SSE \u57fa\u4e8e HTTP\/1.1 \u7684\u5206\u5757\u7f16\u7801&#xff0c;\u5728 HTTP\/2 \u73af\u5883\u540c\u6837\u53ef\u4ee5\u5de5\u4f5c&#xff1b;\u82e5\u90e8\u7f72\u5728\u53cd\u5411\u4ee3\u7406\u6216 CDN&#xff08;\u5982 Nginx\u3001Cloudflare&#xff09;\u540e&#xff0c;\u9700\u8981\u5173\u95ed\u7f13\u51b2\u6216\u4f7f\u7528 proxy_buffering off \u7b49\u6307\u4ee4&#xff0c;\u4ee5\u514d\u4ee3\u7406\u5c06\u4e8b\u4ef6\u6279\u91cf\u7f13\u5b58\u5bfc\u81f4\u5ba2\u6237\u7aef\u6536\u4e0d\u5230\u5b9e\u65f6\u6570\u636e(Cloudflare Docs)\u3002<\/p>\n<h3>\u4e0e\u5176\u4ed6\u5b9e\u65f6\u901a\u4fe1\u6280\u672f\u7684\u5bf9\u6bd4<\/h3>\n<table>\n<tr>\u7ef4\u5ea6SSE (text\/event-stream)WebSocketLong Polling<\/tr>\n<tbody>\n<tr>\n<td>\u8fde\u63a5\u65b9\u5411<\/td>\n<td>\u5355\u5411<\/td>\n<td>\u53cc\u5411<\/td>\n<td>\u5355\u5411<\/td>\n<\/tr>\n<tr>\n<td>\u5efa\u7acb\u6210\u672c<\/td>\n<td>\u666e\u901a HTTP<\/td>\n<td>\u5347\u7ea7\u63e1\u624b<\/td>\n<td>\u591a\u6b21\u77ed\u8fde\u63a5<\/td>\n<\/tr>\n<tr>\n<td>\u4ee3\u7406\u517c\u5bb9<\/td>\n<td>\u53cb\u597d<\/td>\n<td>\u53d6\u51b3\u4e8e\u73af\u5883<\/td>\n<td>\u53cb\u597d<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u636e\u5e27\u683c\u5f0f<\/td>\n<td>\u7b80\u5355\u6587\u672c<\/td>\n<td>\u4e8c\u8fdb\u5236\u5e27<\/td>\n<td>\u5355\u72ec\u54cd\u5e94<\/td>\n<\/tr>\n<tr>\n<td>\u5e94\u7528\u5178\u578b\u573a\u666f<\/td>\n<td>\u5b9e\u65f6\u4eea\u8868\u76d8\u3001\u65e5\u5fd7\u3001\u901a\u77e5<\/td>\n<td>\u534f\u540c\u7f16\u8f91\u3001\u6e38\u620f<\/td>\n<td>\u4f4e\u9891\u5237\u65b0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6587\u7ae0\u9009\u62e9\u7684\u5bf9\u6bd4\u7ef4\u5ea6\u6765\u81ea Ably \u7cfb\u5217\u7814\u7a76\u4e0e\u793e\u533a\u5b9e\u6d4b\u6570\u636e(Ably Realtime, Ably Realtime, Ably Realtime, Ably Realtime, Ably Realtime)&#xff0c;\u5c55\u793a\u4e86 text\/event-stream \u5728\u5355\u5411\u4f4e\u590d\u6742\u5ea6\u63a8\u9001\u573a\u666f\u7684\u4f18\u52bf\u3002<\/p>\n<h3>\u5b9e\u6218&#xff1a;\u7528 Node.js Express \u6784\u5efa\u80a1\u7968\u4ef7\u683c\u63a8\u9001<\/h3>\n<p>\u4e0b\u9762\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u5728 20 \u884c\u5de6\u53f3\u4ee3\u7801\u5185\u5b8c\u6210\u53ef\u751f\u4ea7\u7684 SSE \u670d\u52a1\u3002\u6240\u6709\u53cc\u5f15\u53f7\u5df2\u66ff\u6362\u4e3a\u53cd\u5f15\u53f7\u4ee5\u9075\u5b88\u6392\u7248\u8981\u6c42\u3002<\/p>\n<p>server.js<\/p>\n<p>import express from &#096;express&#096;<\/p>\n<p>const app &#061; express()<br \/>\nconst clients &#061; new Set()<\/p>\n<p>app.get(&#096;\/prices&#096;, (req, res) &#061;&gt; {<br \/>\n  res.writeHead(200, {<br \/>\n    &#096;Content-Type&#096;: &#096;text\/event-stream&#096;,<br \/>\n    &#096;Cache-Control&#096;: &#096;no-cache&#096;,<br \/>\n    Connection: &#096;keep-alive&#096;<br \/>\n  })<br \/>\n  res.write(&#096;:\\\\n\\\\n&#096;)          \/\/ \u7acb\u5373 flush<br \/>\n  clients.add(res)<\/p>\n<p>  req.on(&#096;close&#096;, () &#061;&gt; clients.delete(res))<br \/>\n})<\/p>\n<p>setInterval(() &#061;&gt; {<br \/>\n  const price &#061; (Math.random() * 100).toFixed(2)<br \/>\n  const payload &#061; &#096;data: ${price}\\\\n\\\\n&#096;<br \/>\n  for (const res of clients) res.write(payload)<br \/>\n}, 1000)<\/p>\n<p>app.listen(3000, () &#061;&gt; console.log(&#096;SSE server on :3000&#096;))<\/p>\n<p>index.html<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;meta charset&#061;&#096;utf-8&#096;&gt;<br \/>\n&lt;h1&gt;\u5b9e\u65f6\u80a1\u7968\u4ef7\u683c&lt;\/h1&gt;<br \/>\n&lt;div id&#061;&#096;p&#096;&gt;&lt;\/div&gt;<br \/>\n&lt;script&gt;<br \/>\n  const es &#061; new EventSource(&#096;\/prices&#096;)<br \/>\n  es.onmessage &#061; e &#061;&gt; document.getElementById(&#096;p&#096;).textContent &#061; e.data<br \/>\n&lt;\/script&gt;<\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u76f4\u63a5\u8fd0\u884c\u5373\u53ef\u5728\u6d4f\u89c8\u5668\u770b\u5230\u4ef7\u683c\u9010\u79d2\u8df3\u52a8&#xff0c;\u65e0\u9700\u7b2c\u4e09\u65b9\u5e93&#xff0c;\u5145\u5206\u4f53\u73b0 text\/event-stream \u7684\u8f7b\u91cf\u7279\u6027(Medium, DigitalOcean)\u3002<\/p>\n<h3>\u6027\u80fd\u4e0e\u5b89\u5168\u8003\u91cf<\/h3>\n<ul>\n<li>\n<p>\u8fde\u63a5\u6570\u4e0e\u8d44\u6e90\u5360\u7528 \u6bcf\u4e2a SSE \u8fde\u63a5\u5360\u7528\u4e00\u6761 TCP \u901a\u9053\u548c\u670d\u52a1\u5668\u7ebf\u7a0b\/\u534f\u7a0b&#xff0c;\u767e\u4e07\u7ea7\u5e76\u53d1\u9700\u7ed3\u5408\u65e0\u963b\u585e I\/O\u3001\u8d1f\u8f7d\u5747\u8861\u4e43\u81f3 HTTP\/2 \u8fde\u63a5\u590d\u7528\u7b49\u624b\u6bb5\u6269\u5c55(Ably Realtime)\u3002<\/p>\n<\/li>\n<li>\n<p>CORS \u4e0e\u8ba4\u8bc1 EventSource \u9ed8\u8ba4\u4e0d\u643a\u5e26\u51ed\u8bc1&#xff0c;\u82e5\u9700\u8de8\u57df\u5e76\u9644\u5e26 Cookie&#xff0c;\u5e94\u5728\u6784\u9020\u51fd\u6570\u4f20\u5165 {withCredentials:true} \u5e76\u786e\u4fdd\u670d\u52a1\u5668\u8bbe\u7f6e Access-Control-Allow-Credentials: true \u7b49\u5934\u90e8(Cloudflare Docs)\u3002<\/p>\n<\/li>\n<li>\n<p>\u65ad\u7ebf\u7eed\u4f20 \u5229\u7528 id: \u548c Last-Event-ID \u53ef\u5b9e\u73b0\u5e42\u7b49\u4e0e\u589e\u91cf\u540c\u6b65&#xff0c;\u9632\u6b62\u4e2d\u95f4\u8282\u70b9\u91cd\u8fde\u5bfc\u81f4\u7684\u6570\u636e\u7f3a\u53e3\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ee3\u7406\u8d85\u65f6 \u82e5\u5904\u5728\u542f\u7528\u8fde\u63a5\u7a7a\u95f2\u68c0\u6d4b\u7684\u8d1f\u8f7d\u5747\u8861\u6216 CDN \u4e4b\u540e&#xff0c;\u52a1\u5fc5\u5b9a\u671f\u53d1\u9001\u6ce8\u91ca\u884c\u4fdd\u6d3b&#xff0c;\u6216\u8c03\u6574\u4ee3\u7406\u7684 timeout \u914d\u7f6e&#xff0c;\u907f\u514d\u8fde\u63a5\u88ab\u8bef\u6740(Stack Overflow)\u3002<\/p>\n<\/li>\n<li>\n<p>\u6d41\u91cf\u52a0\u5bc6 SSE \u53ef\u5728 HTTPS \u4e0b\u900f\u660e\u8fd0\u884c&#xff0c;\u4e0e TLS \u63e1\u624b\u5171\u7528\u7aef\u53e3&#xff0c;\u4fdd\u62a4\u6570\u636e\u673a\u5bc6\u6027&#xff1b;\u6d4f\u89c8\u5668\u5b89\u5168\u6a21\u578b\u4e0e\u666e\u901a\u8bf7\u6c42\u4e00\u81f4&#xff0c;\u65e0\u9700\u989d\u5916\u7b56\u7565\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u5178\u578b\u4f7f\u7528\u573a\u666f<\/h3>\n<li>\n<p>\u76d1\u63a7\u4e0e\u544a\u8b66&#xff1a;\u5b9e\u65f6 KPI \u9762\u677f\u3001\u670d\u52a1\u5668\u5065\u5eb7\u5ea6\u63a8\u9001\u3002<\/p>\n<\/li>\n<li>\n<p>\u793e\u4ea4\u52a8\u6001&#xff1a;\u70b9\u8d5e\u8ba1\u6570\u3001\u5fae\u535a\u70ed\u699c\u81ea\u52a8\u5237\u65b0\u3002<\/p>\n<\/li>\n<li>\n<p>\u534f\u4f5c\u5de5\u5177&#xff1a;Markdown \u9884\u89c8\u540c\u6b65\u6e32\u67d3&#xff0c;\u5728\u53ea\u9700\u670d\u52a1\u5668\u5355\u5411\u5e7f\u64ad\u7684\u7f16\u8f91\u5668\u573a\u666f\u5927\u653e\u5f02\u5f69\u3002<\/p>\n<\/li>\n<li>\n<p>\u65e5\u5fd7\u4e0e\u5ba1\u8ba1&#xff1a;DevOps \u63a7\u5236\u53f0\u8f93\u51fa build \u65e5\u5fd7&#xff0c;\u7528\u6237\u7aef\u4e0d\u5fc5\u8f6e\u8be2\u5373\u53ef\u5b9e\u65f6\u83b7\u53d6\u3002<\/p>\n<\/li>\n<li>\n<p>\u7269\u8054\u7f51&#xff1a;\u4f20\u611f\u5668\u6570\u636e\u91c7\u96c6\u540e\u53f0&#xff0c;\u53ea\u4e0a\u4f20\u6d4b\u91cf\u503c&#xff0c;\u65e0\u987b\u6d4f\u89c8\u5668\u53cd\u5411\u6307\u4ee4\u3002<\/p>\n<\/li>\n<p>\u4ee5\u4e0a\u6848\u4f8b\u5e7f\u6cdb\u5b58\u5728\u4e8e\u4e1a\u754c\u4ea7\u54c1\u4e0e\u5f00\u6e90\u7ec4\u4ef6&#xff0c;\u5370\u8bc1\u4e86 text\/event-stream \u7684\u5b9e\u8df5\u4ef7\u503c\u4e0e\u751f\u6001\u6210\u719f\u5ea6(aklivity.io)\u3002<\/p>\n<h3>\u7ed3\u8bed<\/h3>\n<p>text\/event-stream \u7528\u6781\u4f4e\u7684\u5fc3\u667a\u6210\u672c\u4e0e\u7f51\u7edc\u5f00\u9500&#xff0c;\u7ed9\u524d\u7aef\u5e26\u6765\u4e86\u7a33\u5b9a\u3001\u7b80\u5355\u4e14\u53ef\u65ad\u70b9\u7eed\u4f20\u7684\u5b9e\u65f6\u901a\u8baf\u624b\u6bb5\u3002\u5b83\u4e0d\u8ffd\u6c42\u53cc\u5411\u5168\u80fd&#xff0c;\u800c\u662f\u5728\u670d\u52a1\u5668\u53ea\u9700\u8bf4&#xff0c;\u6d4f\u89c8\u5668\u5b89\u9759\u542c\u7684\u6a21\u5f0f\u4e0b&#xff0c;\u628a HTTP \u53d1\u6325\u5230\u4e86\u6781\u81f4\u3002\u82e5\u4f60\u7684\u4e1a\u52a1\u573a\u666f\u4ee5\u5e7f\u64ad\u6216\u8f7b\u91cf\u63a8\u9001\u4e3a\u4e3b&#xff0c;\u4e0d\u60f3\u5728\u4ee3\u7406\u3001\u9632\u706b\u5899\u3001\u4ee3\u7801\u91cf\u4e0a\u4e3a WebSocket \u4ed8\u51fa\u8fc7\u591a\u4ee3\u4ef7&#xff0c;\u90a3\u4e48 SSE \u4e0e text\/event-stream \u4f9d\u65e7\u662f 2025 \u5e74\u503c\u5f97\u91c7\u7528\u7684\u73b0\u4ee3\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb710\u6b21\uff0c\u70b9\u8d5e18\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u7528\u6781\u4f4e\u7684\u5fc3\u667a\u6210\u672c\u4e0e\u7f51\u7edc\u5f00\u9500\uff0c\u7ed9\u524d\u7aef\u5e26\u6765\u4e86\u7a33\u5b9a\u3001\u7b80\u5355\u4e14\u53ef\u65ad\u70b9\u7eed\u4f20\u7684\u5b9e\u65f6\u901a\u8baf\u624b\u6bb5\u3002\u5b83\u4e0d\u8ffd\u6c42\u53cc\u5411\u5168\u80fd\uff0c\u800c\u662f\u5728\u670d\u52a1\u5668\u53ea\u9700\u8bf4\uff0c\u6d4f\u89c8\u5668\u5b89\u9759\u542c\u7684\u6a21\u5f0f\u4e0b\uff0c\u628a HTTP \u53d1\u6325\u5230\u4e86\u6781\u81f4\u3002\u82e5\u4f60\u7684\u4e1a\u52a1\u573a\u666f\u4ee5\u5e7f\u64ad\u6216\u8f7b\u91cf\u63a8\u9001\u4e3a\u4e3b\uff0c\u4e0d\u60f3\u5728\u4ee3\u7406\u3001\u9632\u706b\u5899\u3001\u4ee3\u7801\u91cf\u4e0a\u4e3a WebSocket \u4ed8\u51fa\u8fc7\u591a\u4ee3\u4ef7\uff0c\u90a3\u4e48 SSE \u4e0e\u4f9d\u65e7\u662f 2025 \u5e74\u503c\u5f97\u91c7\u7528\u7684\u73b0\u4ee3\u65b9\u6848\u3002<\/p>\n","protected":false},"author":2,"featured_media":38714,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1202,43,44],"topic":[],"class_list":["post-38715","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-1202","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u7684\u8f7b\u91cf\u957f\u8fde\u63a5\u2014\u2014text\/event-stream \u6df1\u5ea6\u89e3\u6790\u4e0e\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/38715.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u7684\u8f7b\u91cf\u957f\u8fde\u63a5\u2014\u2014text\/event-stream \u6df1\u5ea6\u89e3\u6790\u4e0e\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb710\u6b21\uff0c\u70b9\u8d5e18\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u7528\u6781\u4f4e\u7684\u5fc3\u667a\u6210\u672c\u4e0e\u7f51\u7edc\u5f00\u9500\uff0c\u7ed9\u524d\u7aef\u5e26\u6765\u4e86\u7a33\u5b9a\u3001\u7b80\u5355\u4e14\u53ef\u65ad\u70b9\u7eed\u4f20\u7684\u5b9e\u65f6\u901a\u8baf\u624b\u6bb5\u3002\u5b83\u4e0d\u8ffd\u6c42\u53cc\u5411\u5168\u80fd\uff0c\u800c\u662f\u5728\u670d\u52a1\u5668\u53ea\u9700\u8bf4\uff0c\u6d4f\u89c8\u5668\u5b89\u9759\u542c\u7684\u6a21\u5f0f\u4e0b\uff0c\u628a HTTP \u53d1\u6325\u5230\u4e86\u6781\u81f4\u3002\u82e5\u4f60\u7684\u4e1a\u52a1\u573a\u666f\u4ee5\u5e7f\u64ad\u6216\u8f7b\u91cf\u63a8\u9001\u4e3a\u4e3b\uff0c\u4e0d\u60f3\u5728\u4ee3\u7406\u3001\u9632\u706b\u5899\u3001\u4ee3\u7801\u91cf\u4e0a\u4e3a WebSocket \u4ed8\u51fa\u8fc7\u591a\u4ee3\u4ef7\uff0c\u90a3\u4e48 SSE \u4e0e\u4f9d\u65e7\u662f 2025 \u5e74\u503c\u5f97\u91c7\u7528\u7684\u73b0\u4ee3\u65b9\u6848\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38715.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-21T00:51:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521005103-682d23770d71f.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38715.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38715.html\",\"name\":\"\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u7684\u8f7b\u91cf\u957f\u8fde\u63a5\u2014\u2014text\/event-stream \u6df1\u5ea6\u89e3\u6790\u4e0e\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-21T00:51:04+00:00\",\"dateModified\":\"2025-05-21T00:51:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38715.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38715.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38715.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u7684\u8f7b\u91cf\u957f\u8fde\u63a5\u2014\u2014text\/event-stream \u6df1\u5ea6\u89e3\u6790\u4e0e\u5b9e\u8df5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u7684\u8f7b\u91cf\u957f\u8fde\u63a5\u2014\u2014text\/event-stream \u6df1\u5ea6\u89e3\u6790\u4e0e\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/38715.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u7684\u8f7b\u91cf\u957f\u8fde\u63a5\u2014\u2014text\/event-stream \u6df1\u5ea6\u89e3\u6790\u4e0e\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb710\u6b21\uff0c\u70b9\u8d5e18\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u7528\u6781\u4f4e\u7684\u5fc3\u667a\u6210\u672c\u4e0e\u7f51\u7edc\u5f00\u9500\uff0c\u7ed9\u524d\u7aef\u5e26\u6765\u4e86\u7a33\u5b9a\u3001\u7b80\u5355\u4e14\u53ef\u65ad\u70b9\u7eed\u4f20\u7684\u5b9e\u65f6\u901a\u8baf\u624b\u6bb5\u3002\u5b83\u4e0d\u8ffd\u6c42\u53cc\u5411\u5168\u80fd\uff0c\u800c\u662f\u5728\u670d\u52a1\u5668\u53ea\u9700\u8bf4\uff0c\u6d4f\u89c8\u5668\u5b89\u9759\u542c\u7684\u6a21\u5f0f\u4e0b\uff0c\u628a HTTP \u53d1\u6325\u5230\u4e86\u6781\u81f4\u3002\u82e5\u4f60\u7684\u4e1a\u52a1\u573a\u666f\u4ee5\u5e7f\u64ad\u6216\u8f7b\u91cf\u63a8\u9001\u4e3a\u4e3b\uff0c\u4e0d\u60f3\u5728\u4ee3\u7406\u3001\u9632\u706b\u5899\u3001\u4ee3\u7801\u91cf\u4e0a\u4e3a WebSocket \u4ed8\u51fa\u8fc7\u591a\u4ee3\u4ef7\uff0c\u90a3\u4e48 SSE \u4e0e\u4f9d\u65e7\u662f 2025 \u5e74\u503c\u5f97\u91c7\u7528\u7684\u73b0\u4ee3\u65b9\u6848\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/38715.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-21T00:51:04+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521005103-682d23770d71f.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38715.html","url":"https:\/\/www.wsisp.com\/helps\/38715.html","name":"\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u7684\u8f7b\u91cf\u957f\u8fde\u63a5\u2014\u2014text\/event-stream \u6df1\u5ea6\u89e3\u6790\u4e0e\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-21T00:51:04+00:00","dateModified":"2025-05-21T00:51:04+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38715.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38715.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38715.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6d4f\u89c8\u5668\u4e0e\u670d\u52a1\u5668\u7684\u8f7b\u91cf\u957f\u8fde\u63a5\u2014\u2014text\/event-stream \u6df1\u5ea6\u89e3\u6790\u4e0e\u5b9e\u8df5"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=38715"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38715\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/38714"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38715"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}