Fixed parameter encoding
This commit is contained in:
parent
5eaad56afd
commit
a2636f404d
1 changed files with 16 additions and 22 deletions
|
@ -80,7 +80,10 @@ class JokeApi {
|
||||||
val param = it.next()
|
val param = it.next()
|
||||||
urlBuilder.append(param.key)
|
urlBuilder.append(param.key)
|
||||||
if (param.value.isNotEmpty()) {
|
if (param.value.isNotEmpty()) {
|
||||||
urlBuilder.append("=${param.value}")
|
urlBuilder.append("=").append(
|
||||||
|
URLEncoder.encode(param.value, StandardCharsets.UTF_8).replace("+", "%20")
|
||||||
|
.replace("*", "%2A").replace("%7E", "~")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (it.hasNext()) {
|
if (it.hasNext()) {
|
||||||
urlBuilder.append("&")
|
urlBuilder.append("&")
|
||||||
|
@ -139,7 +142,7 @@ class JokeApi {
|
||||||
|
|
||||||
// Contains
|
// Contains
|
||||||
if (search.isNotBlank()) {
|
if (search.isNotBlank()) {
|
||||||
params[Parameter.CONTAINS] = URLEncoder.encode(search, StandardCharsets.UTF_8).replace("+", "%20")
|
params[Parameter.CONTAINS] = search
|
||||||
}
|
}
|
||||||
|
|
||||||
// Range
|
// Range
|
||||||
|
@ -211,9 +214,7 @@ class JokeApi {
|
||||||
)
|
)
|
||||||
|
|
||||||
413 -> httpException = HttpErrorException(
|
413 -> httpException = HttpErrorException(
|
||||||
responseCode,
|
responseCode, "URI Too Long", IOException("The URL exceeds the maximum length of 250 characters.")
|
||||||
"URI Too Long",
|
|
||||||
IOException("The URL exceeds the maximum length of 250 characters.")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
414 -> httpException = HttpErrorException(
|
414 -> httpException = HttpErrorException(
|
||||||
|
@ -224,22 +225,22 @@ class JokeApi {
|
||||||
|
|
||||||
429 -> httpException = HttpErrorException(
|
429 -> httpException = HttpErrorException(
|
||||||
responseCode, "Too Many Requests", IOException(
|
responseCode, "Too Many Requests", IOException(
|
||||||
"You have exceeded the limit of 120 requests per minute and have to wait a bit" +
|
"You have exceeded the limit of 120 requests per minute and have to wait a bit"
|
||||||
" until you are allowed to send requests again."
|
+ " until you are allowed to send requests again."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
500 -> httpException = HttpErrorException(
|
500 -> httpException = HttpErrorException(
|
||||||
responseCode, "Internal Server Error", IOException(
|
responseCode, "Internal Server Error", IOException(
|
||||||
"There was a general internal error within JokeAPI. You can get more info from" +
|
"There was a general internal error within JokeAPI. You can get more info from"
|
||||||
" the properties in the response text."
|
+ " the properties in the response text."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
523 -> httpException = HttpErrorException(
|
523 -> httpException = HttpErrorException(
|
||||||
responseCode, "Origin Unreachable", IOException(
|
responseCode, "Origin Unreachable", IOException(
|
||||||
"The server is temporarily offline due to maintenance or a dynamic IP update." +
|
"The server is temporarily offline due to maintenance or a dynamic IP update."
|
||||||
" Please be patient in this case."
|
+ " Please be patient in this case."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -262,16 +263,9 @@ class JokeApi {
|
||||||
safe: Boolean = false,
|
safe: Boolean = false,
|
||||||
splitNewLine: Boolean = true
|
splitNewLine: Boolean = true
|
||||||
): Joke {
|
): Joke {
|
||||||
val json =
|
val json = JSONObject(
|
||||||
JSONObject(
|
|
||||||
getRawJoke(
|
getRawJoke(
|
||||||
categories,
|
categories, language, flags, type, search = search, idRange = idRange, safe = safe
|
||||||
language,
|
|
||||||
flags,
|
|
||||||
type,
|
|
||||||
search = search,
|
|
||||||
idRange = idRange,
|
|
||||||
safe = safe
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (json.getBoolean("error")) {
|
if (json.getBoolean("error")) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue