Questions tagged [ktor-client]

145 questions
9
votes
0 answers

Correct way to retrigger loadTokens in Ktor client

In my mobile app, I have a singleton Ktor HttpClient with bearer authentication configured as such: HttpClient(…) { install(Auth) { bearer { sendWithoutRequest { requestBuilder -> some condition } …
gpunto
  • 2,573
  • 1
  • 14
  • 17
9
votes
4 answers

Parsing an error body in a ktor HTTPClient

I have an api that returns error body with the correct error information when a bad request is sent. For eg I get status code 400 and the following body - { "errorCode": 1011, "errorMessage": "Unable to get Child information" } Now when I am…
Kapil G
  • 4,081
  • 2
  • 20
  • 32
7
votes
2 answers

Ktor client Basic Auth does not send the Authorization header

I am trying to use ktor client in Kotlin/MPP (Multiplatform) project and on JVM target feature basic authentication does not seem to have an effect. Here is an example to reproduce: import io.ktor.client.HttpClient import…
kuza
  • 2,761
  • 3
  • 22
  • 56
7
votes
2 answers

How to set a basePath in Ktor similar to Retrofit's `Retrofit.Builder().baseUrl(baseUrl)?

I am trying out Ktor by converting some existing project that's currently using Retrofit. Although I could easily convert the request into something like: client.get { url("$BASE_URL/something/somepage/another") } It seems very tedious to…
Archie G. Quiñones
  • 11,638
  • 18
  • 65
  • 107
7
votes
4 answers

In Ktor, how can I stream an InputStream into a HttpClient Request's body?

I am using Ktor 1.2.2 and I have an InputStream object that I want to use as the body for an HttpClient request I make down the line. Up until Ktor 0.95 there was this InputStreamContent object that seemed to do just that but it has been removed…
spoissant
  • 73
  • 2
  • 6
4
votes
1 answer

How to remove default header for Ktor client 2.0.0

Ktor v2.0.0 for Android. The default ktor header "Accept" just overwrites my "Accept" header. This is the way I am initializing my HttpClient: HttpClient(Android) { defaultRequest { header("Key", BuildConfigCore.API_KEY) …
ghita
  • 2,746
  • 7
  • 30
  • 54
4
votes
1 answer

What is a .api file in the context of Java or Kotlin

I have been looking at the Ktor-client source code on github trying to understand it before making contributions when I came across this file. I see java syntax but I do not understand why it has the extension (.api), plus what it is used for. Any…
OtienoSamwel
  • 316
  • 2
  • 12
4
votes
2 answers

How can I disable Ktor client SSL verification?

I am trying to connect to a service that has a self signed certificate from an internal testing environment that will only exist during prototyping. The Ktor client fails with javax.net.ssl.SSLHandshakeException: PKIX path building failed: …
hanzo2001
  • 1,338
  • 1
  • 10
  • 24
4
votes
2 answers

kotlinx.serialization.SerializationException: Serializer for class 'MultiPartFormDataContent' is not found

I'm trying to upload multiple files. val ktorVersion = "1.5.0" val serializationVersion = "1.0.1" That is how I'm doing that: override suspend fun uploadFiles( binaryFiles: Map ): BaseResponse> { return…
4
votes
1 answer

Put File as Binary with Ktor HttpClient in Kotlin Multiplatform Project

I have a multiplatform project in which api code is shared between iOS and Android. There is "put" api to upload local audio file as Binary. Ive created httpclient as follows val client = HttpClient { defaultRequest { url { …
4
votes
0 answers

Ktor server app keep increasing open connections

Hi i recently deploy ktor server project on server as rest api backend for my app using. I'm using netty and running it on server with system service. Ktor server is running on port 7171 and whenever i check connections with port 7171 it keep…
William
  • 225
  • 4
  • 21
3
votes
2 answers

What is the relationship between non-blocking I/O and Kotlin coroutines?

What is the relationship between Kotlin coroutines and non-blocking I/O? Does one imply the other? What happens if I use blocking I/O? How does this affect performance?
Marco
  • 5,555
  • 2
  • 17
  • 23
3
votes
0 answers

Ktor HttpClient handling close in multiplatform

According to the documentation, we should call close method after we are done with http client instance. What is the right way to handle the close method of ktor http client in multiplatform env. ? In my case, I have a KMM project with android and…
Barracuda
  • 477
  • 5
  • 19
3
votes
2 answers

How to clear bearer tokens in Ktor-client for Android

I am using Ktor client for Android together with the plugin: io.ktor:ktor-client-auth:1.6.4. The current implementation is similar to this snippet. Now I want to implement a 'log out' function when after a button is clicked the tokens are deleted,…
JaySH
  • 546
  • 6
  • 15
3
votes
1 answer

Refresh auth token in Ktor for iOS Http client

I have a KMM project in which I have been using Ktor for the API calls. I have a requirement in which I need to update my access token with the help of refresh tokens if they are expired. Basically I just need to add an authentication module in my…
WhiteSpidy.
  • 1,107
  • 1
  • 6
  • 28
1
2 3
9 10