V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
rulai
V2EX  ›  问与答

这算不算 EventSource 的一个坑

  •  
  •   rulai · Oct 10, 2024 · 1619 views
    This topic created in 578 days ago, the information mentioned may be changed or developed.
    给朋友做一个 chatgpt 流式输出的功能,后端 springboot 传输的数据前面都有一个空白符号,但是前端 vue 收到的数据空格都没有了,换成 EventSourcePolyfill 也是一样,哪位老哥知道怎么解决吗













    5 replies    2024-10-10 17:34:20 +08:00
    zsh2517
        1
    zsh2517  
       Oct 10, 2024
    包装一下,比如做成 JSON 或者 base64 ?
    hsuvee
        2
    hsuvee  
       Oct 10, 2024
    前端别用 EventSource 库,直接 fetch 发请求
    445141126
        3
    445141126  
       Oct 10, 2024
    sse 的第一个空格会被吃掉, 你再加一个空格应该就可以了

    `If value starts with a U+0020 SPACE character, remove it from value.`
    yevXxHmg
        4
    yevXxHmg  
       Oct 10, 2024
    可以尝试下 @microsoft/fetchEventSource 这个包 ,用起来比原生的好用些
    rulai
        5
    rulai  
    OP
       Oct 10, 2024
    @avadakur 原生的 EventSource,EventSourcePolyfill 还有 fetchEventSource 都试过,空格都被截取掉,
    @zsh2517 JSON 格式可以
    @445141126 还真的是,字符串前面自己加个空格就可以了
    感谢 !
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6208 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 122ms · UTC 06:11 · PVG 14:11 · LAX 23:11 · JFK 02:11
    ♥ Do have faith in what you're doing.