Hi, I'm trying the `.sse()` function in Ktor 3.0 ...
# ktor
z
Hi, I'm trying the
.sse()
function in Ktor 3.0 beta 1, and I get
Copy code
io.ktor.sse.SSEException: io.ktor.sse.SSEException: Expected status code 200 but was: 400 at io.ktor.client.plugins.sse.BuildersKt$serverSentEventsSession$2.invokeSuspend(builders.kt:56) at _COROUTINE.BOUNDARY.(CoroutineDebugging.kt:46) at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:230) at kotlinx.coroutines.flow.FlowKt__ErrorsKt.catchImpl(Errors.kt:156) at kotlinx.coroutines.flow.FlowKt__ErrorsKt$catch$$inlined$unsafeFlow$1.collect(Errors.kt:114)
my request body works in other clients. When I get this error, I don't know the response body, and I can't access the response header. It just failed without any way to know why. btw, I also set the
expectSuccess = false
in the client, but it does not work apparently.
when I enabled the logging, I found the request body is empty which causes the 400 error. but the request body is set through
setBody
, the requestBody variable is a json string:
Copy code
.sse(url, request = {
                method = HttpMethod.Post
                headers {
                    append(HttpHeaders.Accept, ContentType.Text.EventStream)
                    append(HttpHeaders.ContentType, ContentType.Application.Json)
                }
                setBody(requestBody)
            }) {...}
all other fields are set allright.
followed the client side debugging, it shows the body was correctly set into HTTPRequestBuilder, but later creating the ClientSSESession, it appears dropped all the body and content type information. I don't know why.
a
Thank you for the issues in YouTrack.
👍 1