Anders Sveen
06/09/2022, 10:41 AMAleksei Tirman [JB]
06/09/2022, 10:45 AMAnders Sveen
06/09/2022, 10:45 AMHttpClient(OkHttp) {
install(Logging) {
level = LogLevel.ALL
}
install(ContentNegotiation) {
jackson()
}
install(HttpTimeout) { // set long timeout to avoid timeouts when getting account entries
requestTimeoutMillis = 60000
}
expectSuccess = false
}
Anders Sveen
06/09/2022, 10:47 AMpost("${apiHostName}/api/consents") {
header("Authorization", "Bearer ${accessToken.accessToken}")
header("Content-Type", "application/json")
header("Idempotency-Key", UUID.randomUUID())
setBody(json)
}
Anders Sveen
06/09/2022, 10:48 AMAnders Sveen
06/09/2022, 10:48 AMAnders Sveen
06/09/2022, 10:54 AM2022-06-09 11:08:41.418 [Test worker @coroutine#34] [] INFO io.ktor.client.HttpClient - REQUEST: <https://api.test.com/api/consents>
METHOD: HttpMethod(value=POST)
COMMON HEADERS
-> Accept: application/json
-> Accept-Charset: UTF-8
-> Authorization: Bearer XXX
-> Idempotency-Key: 777eadc5-c8da-47bd-98aa-de7a9a1cb99e
-> PSU-IP-Address: 188.95.241.148
CONTENT HEADERS
-> Content-Type: application/json
2022-06-09 11:08:41.448 [DefaultDispatcher-worker-2 @coroutine#46] [] INFO io.ktor.client.HttpClient - BODY Content-Type: application/json
BODY START
{"account":"TX99998","callbackUrl":"<https://something>"}
BODY END
2022-06-09 11:08:41.642 [DefaultDispatcher-worker-2 @ktor-okhttp-context#52] [] INFO io.ktor.client.HttpClient - RESPONSE: 400
METHOD: HttpMethod(value=POST)
FROM: <https://api.test.com/api/consents>
COMMON HEADERS
-> cache-control: no-store, no-cache, must-revalidate, proxy-revalidate
-> content-length: 0
-> content-security-policy: default-src 'self'
-> date: Thu, 09 Jun 2022 09:08:41 GMT
-> expires: 0
-> pragma: no-cache
-> server: istio-envoy
-> strict-transport-security: max-age=5184000; includeSubDomains; preload
-> surrogate-control: no-store
-> x-content-security-policy: default-src 'self'
-> x-content-type-options: nosniff
-> x-envoy-upstream-service-time: 116
-> x-frame-options: DENY
-> x-webkit-csp: default-src 'self'
-> x-xss-protection: 1; mode=block
BODY Content-Type: null
BODY START
BODY END
Aleksei Tirman [JB]
06/09/2022, 10:54 AMContent-Length
header is omitted because the Transfer-Encoding
is chunked
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding#chunkedAnders Sveen
06/09/2022, 10:55 AMAleksei Tirman [JB]
06/09/2022, 10:55 AMPOST /post HTTP/1.1
Authorization: Bearer token
Idempotency-Key: 320e4bb4-9c73-4d36-8ad1-722ffd3f8203
Accept: application/json
Accept-Charset: UTF-8
User-Agent: Ktor client
Content-Type: application/json
Transfer-Encoding: chunked
Host: <http://httpbin.org|httpbin.org>
Connection: Keep-Alive
Accept-Encoding: gzip
Anders Sveen
06/09/2022, 10:56 AMAleksei Tirman [JB]
06/09/2022, 10:56 AMAleksei Tirman [JB]
06/09/2022, 10:57 AMHjm... And you get that with the config I set above? So with OkHttp?Yes
Aleksei Tirman [JB]
06/09/2022, 10:57 AMval client = HttpClient(OkHttp) {
install(Logging) {
level = LogLevel.ALL
}
install(ContentNegotiation) {
jackson()
}
install(HttpTimeout) { // set long timeout to avoid timeouts when getting account entries
requestTimeoutMillis = 60000
}
expectSuccess = false
}
val r = <http://client.post|client.post>("<http://httpbin.org/post>") {
header("Authorization", "Bearer token")
header("Content-Type", "application/json")
header("Idempotency-Key", UUID.randomUUID())
setBody(mapOf("foo" to "bar"))
}.bodyAsText()
println(r)
Anders Sveen
06/09/2022, 10:58 AMAleksei Tirman [JB]
06/09/2022, 10:58 AMAnders Sveen
06/09/2022, 11:12 AMAleksei Tirman [JB]
06/09/2022, 11:13 AMContent-Length
header in my request.Anders Sveen
06/09/2022, 11:24 AMrocketraman
06/09/2022, 1:15 PMAnders Sveen
06/09/2022, 1:16 PMAleksei Tirman [JB]
06/09/2022, 3:42 PMAnders Sveen
06/09/2022, 4:09 PMAleksei Tirman [JB]
06/09/2022, 4:10 PMAnders Sveen
06/09/2022, 4:13 PMAleksei Tirman [JB]
06/09/2022, 4:13 PMAnders Sveen
06/13/2022, 1:24 PMsetBody(ByteArrayContent(jsonString.toByteArray(), ContentType.Application.Json, HttpStatusCode.OK))
A bit worrying, but only an issue in our test code. So won't dig further for now. Thanks for helping. 🙂