Ktor: Does ktor-client allow setting proxy with authentication?

Created on 27 Nov 2018  路  2Comments  路  Source: ktorio/ktor

Hello,

I didn't find anywhere information regarding the possibility of making ktor-client requests using proxy with authentication.

Is it possible at all?

Most helpful comment

I've found that it can be done with Apache client:

private val client = io.ktor.client.HttpClient(Apache) {
        engine {
            followRedirects = true

            customizeClient {
                setProxy(HttpHost(proxyDetails.host, proxyDetails.port))

                val credentialsProvider = BasicCredentialsProvider()
                credentialsProvider .setCredentials(AuthScope(proxyHost, proxyPort),
                    UsernamePasswordCredentials(proxyUsername, proxyPassword))

                setDefaultCredentialsProvider(credentialsProvider )
            }
        }
    }

All 2 comments

I've found that it can be done with Apache client:

private val client = io.ktor.client.HttpClient(Apache) {
        engine {
            followRedirects = true

            customizeClient {
                setProxy(HttpHost(proxyDetails.host, proxyDetails.port))

                val credentialsProvider = BasicCredentialsProvider()
                credentialsProvider .setCredentials(AuthScope(proxyHost, proxyPort),
                    UsernamePasswordCredentials(proxyUsername, proxyPassword))

                setDefaultCredentialsProvider(credentialsProvider )
            }
        }
    }

Is there a way to do it multiplatform ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PatrickLemke picture PatrickLemke  路  3Comments

ManifoldFR picture ManifoldFR  路  4Comments

gabin8 picture gabin8  路  3Comments

lamba92 picture lamba92  路  3Comments

diaodou picture diaodou  路  3Comments