post可以正确识别contentType

pull/1470/head
gedoor 3 years ago
parent 8901926050
commit 60b61184d6
  1. 9
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  2. 6
      app/src/main/java/io/legado/app/utils/StringExtensions.kt

@ -17,6 +17,8 @@ import io.legado.app.help.http.*
import io.legado.app.model.ConcurrentException import io.legado.app.model.ConcurrentException
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response import okhttp3.Response
import java.net.URLEncoder import java.net.URLEncoder
import java.util.* import java.util.*
@ -207,7 +209,7 @@ class AnalyzeUrl(
} }
} }
RequestMethod.POST -> body?.let { RequestMethod.POST -> body?.let {
if (!it.isJson()) { if (!it.isJson() && !it.isXml()) {
analyzeFields(it) analyzeFields(it)
} }
} }
@ -391,8 +393,13 @@ class AnalyzeUrl(
when (method) { when (method) {
RequestMethod.POST -> { RequestMethod.POST -> {
url(urlNoQuery) url(urlNoQuery)
val contentType = headerMap["Content-Type"]
val body = body
if (fieldMap.isNotEmpty() || body.isNullOrBlank()) { if (fieldMap.isNotEmpty() || body.isNullOrBlank()) {
postForm(fieldMap, true) postForm(fieldMap, true)
} else if (!contentType.isNullOrBlank()) {
val requestBody = body.toRequestBody(contentType.toMediaType())
post(requestBody)
} else { } else {
postJson(body) postJson(body)
} }

@ -47,6 +47,12 @@ fun String?.isJsonArray(): Boolean =
str.startsWith("[") && str.endsWith("]") str.startsWith("[") && str.endsWith("]")
} ?: false } ?: false
fun String?.isXml(): Boolean =
this?.run {
val str = this.trim()
str.startsWith("<") && str.endsWith(">")
} ?: false
fun String.splitNotBlank(vararg delimiter: String): Array<String> = run { fun String.splitNotBlank(vararg delimiter: String): Array<String> = run {
this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray()
} }

Loading…
Cancel
Save