diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 81b11e51b..589b511d8 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -17,6 +17,8 @@ import io.legado.app.help.http.* import io.legado.app.model.ConcurrentException import io.legado.app.utils.* import kotlinx.coroutines.runBlocking +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response import java.net.URLEncoder import java.util.* @@ -207,7 +209,7 @@ class AnalyzeUrl( } } RequestMethod.POST -> body?.let { - if (!it.isJson()) { + if (!it.isJson() && !it.isXml()) { analyzeFields(it) } } @@ -391,8 +393,13 @@ class AnalyzeUrl( when (method) { RequestMethod.POST -> { url(urlNoQuery) + val contentType = headerMap["Content-Type"] + val body = body if (fieldMap.isNotEmpty() || body.isNullOrBlank()) { postForm(fieldMap, true) + } else if (!contentType.isNullOrBlank()) { + val requestBody = body.toRequestBody(contentType.toMediaType()) + post(requestBody) } else { postJson(body) } diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index 1e57f6416..d026812e8 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -47,6 +47,12 @@ fun String?.isJsonArray(): Boolean = str.startsWith("[") && str.endsWith("]") } ?: false +fun String?.isXml(): Boolean = + this?.run { + val str = this.trim() + str.startsWith("<") && str.endsWith(">") + } ?: false + fun String.splitNotBlank(vararg delimiter: String): Array = run { this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() }