Добавьте пролог xml в Retrofit и SimpleXml - PullRequest
0 голосов
/ 26 марта 2020

Я пытаюсь создать SOAP POST-запрос, который включает пролог xml в верхней части содержимого:

<?xml version="1.0" encoding="utf-8"?>

Как мне этого добиться? По умолчанию он не добавляется.

Модификация:

    val strategy: Strategy = AnnotationStrategy()
    val serializer: Serializer = Persister(strategy)

    Retrofit.Builder()
        .addConverterFactory(SimpleXmlConverterFactory.create(serializer))
        .baseUrl("http://example.com/")
        .client(
            OkHttpClient.Builder()
                .connectTimeout(TIMEOUT, TimeUnit.SECONDS)
                .readTimeout(TIMEOUT, TimeUnit.SECONDS)
                .writeTimeout(TIMEOUT, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                .addInterceptor(
                    HttpLoggingInterceptor().apply {
                        level = HttpLoggingInterceptor.Level.BODY
                    }
                ).build()
        )
        .build()
        .create(Api::class.java)

API:

@Headers(
    "Accept: text/xml",
    "Content-Type: text/xml; charset=\"utf-8\"",
    "Connection: Keep-Alive"
)
@POST("/mypath")
suspend fun getThis(@Body body: MyEnvelope): Response<MyEnvelope>
...