Marko Kunic
11/04/2021, 9:32 AMType mismatch.
Required: HeaderValueWithParameters
Found: String
HeaderValueWithParameters is abstract, not sure what to pass here?Aleksei Tirman [JB]
11/04/2021, 9:37 AMAleksei Tirman [JB]
11/04/2021, 9:39 AM<http://client.post|client.post><String>("<https://example.com>") {
headers {
append("name", "value")
}
}
Marko Kunic
11/04/2021, 9:40 AMclient.request(uri.toString()) {
headers {
@OptIn(InternalAPI::class)
append("test", "test")
}
HttpMethod(mymethod.toString())
body = mybody
}
Marko Kunic
11/04/2021, 9:44 AMMarko Kunic
11/04/2021, 11:16 AMappend
from io.ktor.http
and not io.ktor.util
, docs mention later, while my code is using formerAleksei Tirman [JB]
11/04/2021, 11:19 AMappend
is imported from io.ktor.http
package):
import io.ktor.client.*
import io.ktor.client.engine.apache.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.util.InternalAPI
import kotlinx.coroutines.coroutineScope
suspend fun main(): Unit = coroutineScope {
val client = HttpClient(Apache) {}
client.request("<https://httpbin.org/post>") {
headers {
@OptIn(InternalAPI::class)
append("test", "test")
}
method = <http://HttpMethod.Post|HttpMethod.Post>
body = "body"
}
}
Marko Kunic
11/04/2021, 11:20 AMMarko Kunic
11/04/2021, 11:21 AMMarko Kunic
11/04/2021, 11:28 AMMarko Kunic
11/04/2021, 12:17 PMimport com.mycompany.sdk.other.API.HttpMethod
import com.mycompany.sdk.other.API.HttpClient
import com.mycompany.sdk.other.API.Response
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.util.InternalAPI;
import kotlinx.coroutines.runBlocking
import java.net.URI
import io.ktor.client.HttpClient as InnerKtorHttpClient
import io.ktor.http.HttpMethod as KtorHttpMethod
class KtorHttpClient(private val client: InnerKtorHttpClient) : HttpClient {
override fun request(uri: URI, method: HttpMethod, body: String, headers: Map<String, String>): Response {
val response: HttpResponse = runBlocking {
client.request(uri.toString()) {
headers {
@OptIn(InternalAPI::class)
headers.forEach { header -> append(header.key, header.value) }
}
KtorHttpMethod(method.toString())
this.body = body
}
}
return Response(response.status.value, response.toString())
}
}
this is my real code if it makes a difference?Aleksei Tirman [JB]
11/05/2021, 9:48 AMMarko Kunic
11/05/2021, 10:05 AMAleksei Tirman [JB]
11/05/2021, 12:47 PM