|
|
|
@ -51,8 +51,8 @@ class AnalyzeUrl( |
|
|
|
|
private var queryStr: String? = null |
|
|
|
|
private val fieldMap = LinkedHashMap<String, String>() |
|
|
|
|
private var charset: String? = null |
|
|
|
|
private var bodyTxt: String? = null |
|
|
|
|
private var body: RequestBody? = null |
|
|
|
|
private var body: Any? = null |
|
|
|
|
private var requestBody: RequestBody? = null |
|
|
|
|
private var method = RequestMethod.GET |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
@ -157,15 +157,25 @@ class AnalyzeUrl( |
|
|
|
|
baseUrl = it |
|
|
|
|
} |
|
|
|
|
if (urlArray.size > 1) { |
|
|
|
|
val options = GSON.fromJsonObject<Map<String, String>>(urlArray[1]) |
|
|
|
|
val options = GSON.fromJsonObject<UrlOption>(urlArray[1]) |
|
|
|
|
options?.let { _ -> |
|
|
|
|
options["method"]?.let { if (it.equals("POST", true)) method = RequestMethod.POST } |
|
|
|
|
options["headers"]?.let { headers -> |
|
|
|
|
GSON.fromJsonObject<Map<String, String>>(headers)?.let { headerMap.putAll(it) } |
|
|
|
|
options.method?.let { if (it.equals("POST", true)) method = RequestMethod.POST } |
|
|
|
|
options.headers?.let { headers -> |
|
|
|
|
if (headers is Map<*, *>) { |
|
|
|
|
headerMap.putAll(headers as Map<out String, String>) |
|
|
|
|
} |
|
|
|
|
if (headers is String) { |
|
|
|
|
GSON.fromJsonObject<Map<String, String>>(headers) |
|
|
|
|
?.let { headerMap.putAll(it) } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
body = options.body |
|
|
|
|
charset = options.charset |
|
|
|
|
options.webView?.let { |
|
|
|
|
if (it.toString().isNotEmpty()) { |
|
|
|
|
useWebView = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
options["body"]?.let { bodyTxt = it } |
|
|
|
|
options["charset"]?.let { charset = it } |
|
|
|
|
options["webView"]?.let { if (it.isNotEmpty()) useWebView = true } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
when (method) { |
|
|
|
@ -179,11 +189,11 @@ class AnalyzeUrl( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
RequestMethod.POST -> { |
|
|
|
|
bodyTxt?.let { |
|
|
|
|
if (it.isJson()) { |
|
|
|
|
body = RequestBody.create(jsonType, it) |
|
|
|
|
} else { |
|
|
|
|
body?.let { |
|
|
|
|
if (it is String) { |
|
|
|
|
analyzeFields(it) |
|
|
|
|
} else { |
|
|
|
|
body = RequestBody.create(jsonType, GSON.toJson(it)) |
|
|
|
|
} |
|
|
|
|
} ?: let { |
|
|
|
|
body = FormBody.Builder().build() |
|
|
|
@ -253,7 +263,7 @@ class AnalyzeUrl( |
|
|
|
|
} else { |
|
|
|
|
HttpHelper |
|
|
|
|
.getApiService<HttpPostApi>(baseUrl, charset) |
|
|
|
|
.postBody(url, body!!, headerMap) |
|
|
|
|
.postBody(url, requestBody!!, headerMap) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fieldMap.isEmpty() -> HttpHelper |
|
|
|
@ -277,7 +287,7 @@ class AnalyzeUrl( |
|
|
|
|
params.requestMethod = method |
|
|
|
|
params.javaScript = jsStr |
|
|
|
|
params.sourceRegex = sourceRegex |
|
|
|
|
params.postData = bodyTxt?.toByteArray() |
|
|
|
|
params.postData = body?.toString()?.toByteArray() |
|
|
|
|
params.tag = tag |
|
|
|
|
return HttpHelper.ajax(params) |
|
|
|
|
} |
|
|
|
@ -294,7 +304,7 @@ class AnalyzeUrl( |
|
|
|
|
} else { |
|
|
|
|
HttpHelper |
|
|
|
|
.getApiService<HttpPostApi>(baseUrl, charset) |
|
|
|
|
.postBodyAsync(url, body!!, headerMap) |
|
|
|
|
.postBodyAsync(url, requestBody!!, headerMap) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fieldMap.isEmpty() -> HttpHelper |
|
|
|
@ -307,4 +317,12 @@ class AnalyzeUrl( |
|
|
|
|
return Res(NetworkUtils.getUrl(res), res.body()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
data class UrlOption( |
|
|
|
|
val method: String?, |
|
|
|
|
val charset: String?, |
|
|
|
|
val webView: Any?, |
|
|
|
|
val headers: Any?, |
|
|
|
|
val body: Any? |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|