EventSouce in rust?

Does anyone know about reqwest's EventSource?
I'm using reqwest-eventsource crate to send a POST request to a website and receive the corresponding stream.

However, I've encountered an issue:
When I use reqwest's post API (awaiting for the server to send complete information), the received messages are completely normal. But when using this library, each sent event gets stuck at line 288 until the server terminates the connection.
My code is no different from the official sample code, except that I need to use POST to fulfill my requirements.
At the same time, I confirm that my code works fine when connecting to the local actix-web SSE service.

Here is my modified version of the log.
And here is the corresponding output information.
Does anyone know how to troubleshoot this issue?

Are you saying the event source library works fine when connecting to a local service, but not to demo.mygpt.com (the URL in your log file)? If so, it sounds like an issue with the remote service.

Yes, it sounds like a server issue, but in fact it is not. The API works fine on the webpage, which indicates that JavaScript can receive its events properly. Moreover, I am able to receive data in a "synchronously" way:

client.await.post("demo.mygpt.com")
            .headers(HEADER_MAP.clone())
            .json(&MyRequest {
                prompt,
                parent_message_id,
            })
            .send()
            .await

This will end the await after it has sent all the data and return the complete information to me, but I hope it can receive the data one by one like chatgpt webpage.

I'm not an expert on SSE, but the standard apparently doesn't support POST requests, e.g. see this:

That doesn't mean a hack couldn't be made to get POST working somehow, but if it's not part of the standard, then I guess this isn't really a bug in the reqwest-eventsource crate, and you might have to work out some kind of hacky fix yourself. If the JS interface that you say works properly uses GET instead of POST, it might be better to emulate that.

In fact, it seems that the web pages related to ChatGPT are using the POST method to use EventSource, so I'm not sure where the problem might be.

This is also what I want to ask. I want to pinpoint the specific location of the issue, but so far I haven't found any way to try troubleshooting. Therefore, I hope to find a reliable way to identify the problem or if there are other ways to use this API.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.