Пример функции из SoapClient.kt:
Код: Выделить всё
fun getSomething(context: Context): List {
val namespace = "NAMESPACE"
val methodName = "GetSomething"
val soapAction = "$namespace/FIXEDVALUE/$methodName"
val urlString = getServiceUrl(context)
val request = SoapObject(namespace, methodName)
val username = "USERNAME"
val password = "PASSWORD"
request.addProperty("username", USERNAME)
request.addProperty("password", PASSWORD)
val envelope = SoapSerializationEnvelope(SoapEnvelope.VER11).apply {
dotNet = true
setOutputSoapObject(request)
}
val headerList = listOf(
HeaderProperty("soapAction", soapAction)
)
try {
val url = URL(urlString)
val keyStore = KeyStore.getInstance("PKCS12").apply {
load(context.resources.openRawResource(R.raw.CERTIFIKAT), "SIFRA".toCharArray())
}
val keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()).apply {
init(keyStore, "SIFRA".toCharArray())
}
val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()).apply {
init(keyStore)
}
val sslContext = SSLContext.getInstance("TLS").apply {
init(keyManagerFactory.keyManagers, trustManagerFactory.trustManagers, null)
}
val transport = CustomHttpsTransportSE(url.host, url.port, url.file, 60000, sslContext.socketFactory)
transport.debug = true
transport.call(soapAction, envelope, headerList)
val response = envelope.response as SoapObject
return response
} catch (e: Exception) {
e.printStackTrace()
return emptyList()
}
}
Код: Выделить всё
class CustomHttpsTransportSE(
host: String,
port: Int,
file: String,
timeout: Int,
private val sslSocketFactory: SSLSocketFactory
) : HttpsTransportSE(host, port, file, timeout) {
}
Я пробовал много вещей, но не смог Нигде не нашел ни точного решения этой проблемы, ни полного кода, который мог бы мне помочь.
Подробнее здесь: https://stackoverflow.com/questions/790 ... ap2-kotlin
Мобильная версия