Sahil0shrma
06/21/2024, 12:39 PMI'm encountering an issue with Ktor's HttpClient when setting a default base URL. Here's my setup:
val client = HttpClient(engine) {
defaultRequest {
// Setting default base URL for requests
url("<https://example.com>")
}
}
When I make a request to a relative path, it works as expected:
client.get {
url("/sampleApi")
}
// This correctly calls "<https://example.com/sampleApi>"
However, the problem arises when I try to make a request to a different domain with a different protocol:
client.get {
url("<http://anotherdomain.com/sampleApi>")
}
// This results in "<https://anotherdomain.com/sampleApi>", overriding the protocol to https
The default protocol (https) is being applied to the entire URL, and it changes http
to https
for the new domain.
Has anyone faced a similar issue or knows how to ensure the protocol specified in the URL remains unchanged? Any help or pointers would be greatly appreciated!
Thanks!Bruce Hamilton
06/21/2024, 1:05 PM