Hi All, I'm requesting to the backend with login c...
# ktor
j
Hi All, I'm requesting to the backend with login credentials and the backend set cookies if login was successful. So, how i could read the cookies using ktor client? I've tried
AcceptAllCookiesStorage
but not working
a
Do you need to read cookies or store them to use for the subsequent requests?
j
Both would be nice to learn
Do I need to setup session plugin as cookies in ktor
httclient{}
a
You can get the
Set-Cookie
header from the response by using the
HttpResponse.setCookie
:
Copy code
val client = HttpClient(CIO)
val response = client.get("")
println(response.setCookie())
For automatic cookie management you can use the HttpCookies plugin.
j
Does setCookie return the cookies?
a
It returns list of names/values parsed from the
Set-Cookie
header
j
I'm using js engine and I didn't find any cookie but I can see in the network tab of the browser that cookie is available
This is my config. Body is fine. but i think there is a bug while parsing cookies
a
A web browser doesn't allow to directly read and send cookies.
j
what i could do?
a
Also, there is an issue https://youtrack.jetbrains.com/issue/KTOR-539 about using browser cookie storage.
You can use the Fetch API directly without Ktor.
j
My app is targetting android and web.
a
You can abstract away your HTTP API through expect/actual keywords if you use KMP.
j
okay. I'll try. Thanks