https://kotlinlang.org logo
Title
b

bitkid

08/30/2019, 11:44 AM
hi! how can i tell the http client to allow a string as body when content-type = application/json? as soon as i set that header i get the exception "class java.lang.String cannot be cast to class io.ktor.client.call.HttpClientCall"
works with
body = TextContent("""{"name": "$it", "repository":"GE_VIENNA", "rows":10, "metaData": $meta}""", ContentType.Application.Json)
d

Dominaezzz

08/30/2019, 11:54 AM
Try setting
body
to TextContent
Yup
b

bitkid

08/30/2019, 11:54 AM
hehe thx
i am using HttpClient(CIO)
at one point i am getting the exception
Exception in thread "main" java.net.BindException: Address already in use: no further information
@Dominaezzz any ideas whats happening there?
d

Dominaezzz

08/30/2019, 11:56 AM
That's unusual for a client I think.
You're not doing any server stuff?
b

bitkid

08/30/2019, 11:57 AM
i am doing 30k calls in a short time
HttpClient(CIO).use { client ->
            metadata.keys.forEach {
                val meta = jackson.writeValueAsString(metadata.getValue(it))
                client.call {
                    url("$baseUrl/api/matrices/create")
                    method = <http://HttpMethod.Post|HttpMethod.Post>
                    body = TextContent("""{"name": "$it", "repository":"GE_VIENNA", "rows":10, "metaData": $meta}""", ContentType.Application.Json)
                }.close()
            }
        }
it never succeeds
d

Dominaezzz

08/30/2019, 11:59 AM
Hmm, might be a bug in
CIO
. Have you tried
Apache
?
b

bitkid

08/30/2019, 11:59 AM
no .. trying it now. is apache the most stable one?
d

Dominaezzz

08/30/2019, 12:00 PM
It's a stable one with the most config.
Only
CIO
is experimental.
b

bitkid

08/30/2019, 12:07 PM
works with the apache client
same code
d

Dominaezzz

08/30/2019, 1:30 PM
Yeah, make a big report when you can.
b

bitkid

08/30/2019, 2:02 PM
i will