ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
12.86k stars 1.04k forks source link

XML client #1570

Open rndev-io opened 4 years ago

rndev-io commented 4 years ago

Subsystem Client

Is your feature request related to a problem? Please describe. I want to make http requests to XML API.

Describe the solution you'd like Create ktor-client-xml like ktor-client-json to (de-) serialize request/response.

Motivation to include to ktor XML very popular format for data transferring.

rwsbillyang commented 4 years ago

any progress? In my project, xml format data is needed. I am figuring how to do...

dstibbe commented 4 years ago

You can make xml requests already. Use the JsonFeature and provide a serializer with the jackson xml mapper and the "application/xml" content-type:

val client = HttpClient(MockEngine) {
  install(JsonFeature) {
    serializer = JacksonSerializer(jackson = XmlMapper().registerModule(KotlinModule()))
    accept(ContentType.Application.Xml)
  }
}
oleg-larshin commented 4 years ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

jlengrand commented 3 years ago

Just adding something because I spent some time before finding out the problem : Do check in the headers which kind of content you're receiving from your server. In my case, I was receiving Content-Type: text/xml and I had to adapt to accept(ContentType.Text.Xml), as application wouldn't grab my transformer. Otherwise, can confirm that XML serialization works like a charm.