From f7b5407786146e03596f107776207108cb26b6bb Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 3 Jul 2019 10:27:03 +0800 Subject: [PATCH] up --- .../app/model/analyzeRule/AnalyzeUrl.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 c16c7f37b..273b76fad 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 @@ -46,6 +46,7 @@ class AnalyzeUrl( private val queryMap = LinkedHashMap() private val headerMap = HashMap() private var charset: String? = null + private var bodyTxt: String? = null var body: RequestBody? = null private set var method = Method.GET @@ -121,7 +122,7 @@ class AnalyzeUrl( * 处理URL */ private fun initUrl() { - val urlArray = ruleUrl.split(",[^\\{]*".toRegex(), 2) + var urlArray = ruleUrl.split(",[^\\{]*".toRegex(), 2) url = urlArray[0] host = NetworkUtils.getBaseUrl(url) if (urlArray.size > 1) { @@ -133,10 +134,22 @@ class AnalyzeUrl( headers )?.let { headerMap.putAll(it) } } - options["body"]?.let { } + options["body"]?.let { bodyTxt = it } options["charset"]?.let { charset = it } } } + when (method) { + Method.GET -> { + urlArray = url.split("\\?".toRegex()) + url = urlArray[0] + if (urlArray.size > 1) { + analyzePutFields(urlArray[1]) + } + } + Method.POST -> { + bodyTxt + } + } } @@ -144,9 +157,9 @@ class AnalyzeUrl( * 解析QueryMap */ @Throws(Exception::class) - private fun analyzeQuery(allQuery: String) { - queryStr = allQuery - val queryS = allQuery.split("&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + private fun analyzePutFields(fieldsTxt: String) { + queryStr = fieldsTxt + val queryS = fieldsTxt.split("&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() for (query in queryS) { val queryM = query.split("=".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() val value = if (queryM.size > 1) queryM[1] else ""