sindrenm
04/13/2022, 11:09 AMHttpRequestBuilder
when configuring DefaultRequest
, but I'm instead in the scope of a DefaultRequestBuilder
. AFAICT, they don't share the same structure. Previously, in ktor-client v1.6.7, I was able to access body
inside of this builder scope, but no more.
Docs:
val client = HttpClient(CIO) {
defaultRequest {
// this: HttpRequestBuilder
}
}
Actual (ktor-client-core-jvm-2.0.0.jar):
public class DefaultRequest private constructor(private val block: DefaultRequestBuilder.() -> Unit) {
public companion object Plugin : HttpClientPlugin<DefaultRequestBuilder, DefaultRequest> {
// ...
}
// ...
}
// Hence:
defaultRequest {
// this: io.ktor.client.plugins.DefaultRequest.DefaultRequestBuilder
}
Is this by design? Are the docs wrong here?hfhbd
04/13/2022, 11:15 AMsindrenm
04/13/2022, 11:17 AMFormDataContent
and if it is, we're overriding the content type of the request. I'm not sure of the reasoning behind this, though, but I'm assuming there is one. 😅Aleksei Tirman [JB]
04/13/2022, 11:28 AMsindrenm
04/13/2022, 11:36 AM.submitForm
and changing the Content-Type to application/json, when we should probably just to a regular .post
, so I'm gonna try that now. 😅ContentNegotiation
plugin (configured with io.ktor.serialization.kotlinx.json.JsonSupportKt#json()
) kicks in and serializes the body, or is there a more correct approach to that?Aleksei Tirman [JB]
04/13/2022, 12:49 PMMultiPartFormDataContent
sets the Content-Type
with a boundary so you can’t just override the header manually.sindrenm
04/13/2022, 12:59 PMdefaultRequest
and make a request using submitForm()
, it would still be using the application/json (default request) Content-Type, right? I imagine that's the reason we had that check in the first place. Or will MultiPartFormDataContent
then make sure that the Content-Type is overridden from application/json to the proper Content-Type?Aleksei Tirman [JB]
04/13/2022, 3:11 PMBut if I set a Content-Type application/json inYes. And if theand make a request usingdefaultRequest
, it would still be using the application/json (default request) Content-Type, right?submitForm()
ContentNegotiation
plugin is installed then it will try to serialize an MultiPartFormDataContent
object.sindrenm
04/13/2022, 6:55 PM