티스토리 뷰
object RestUtil : Loggable {
const val RETRIES = 3
const val TIMEOUT = 5 * 60 * 1000
private const val MAX_BODY_SIZE = 0
private const val IGNORE_CONTENT_TYPE = true
fun connection(
url: String,
json: String,
headers: Map<String, String> = emptyMap(),
data: Map<String, String>? = emptyMap(),
timeout: Int? = TIMEOUT
): Connection {
var connection = Jsoup.connect(url)
headers.forEach {
connection = connection.header(it.key, it.value)
}
data!!.forEach {
connection = connection.data(it.key, it.value)
}
return connection
.timeout(timeout!!)
.maxBodySize(MAX_BODY_SIZE)
.ignoreContentType(IGNORE_CONTENT_TYPE)
.requestBody(json)
}
inline fun <reified T> get(
url: String,
json: String,
headers: Map<String, String> = emptyMap(),
data: Map<String, String>? = emptyMap(),
retries: Int? = RETRIES,
timeout: Int? = TIMEOUT,
): T {
var text: String? = null
run loop@{
repeat(retries!!) {
try {
text = connection(url, json, headers, data, timeout = timeout)
.get()
.text()
return@loop
} catch (expected: Exception) {
logger.error(expected.message, expected)
}
}
}
if (text == null) {
throw NotFoundException()
}
return try {
text!!.toObject()
} catch (expected: Exception) {
text as T
}
}
inline fun <reified T> post(
url: String,
json: String,
headers: Map<String, String> = emptyMap(),
data: Map<String, String>? = emptyMap(),
retries: Int? = RETRIES,
timeout: Int? = TIMEOUT,
): T {
var text: String? = null
run loop@{
repeat(retries!!) {
try {
text = connection(url, json, headers, data, timeout = timeout)
.post()
.text()
return@loop
} catch (expected: Exception) {
logger.error(expected.message, expected)
}
}
}
if (text == null) {
throw NotFoundException()
}
return try {
text!!.toObject()
} catch (expected: Exception) {
text as T
}
}
}
https://stackoverflow.com/questions/10506577/jsoup-connections-and-retries
Jsoup connections and retries
I'm using JSoup to connect to a website. I sometimes find that JSoupwill have a connection timeout, when this happens I want JSoup to retry the connection and when it fails on the 3rd time it sha...
stackoverflow.com
https://stackoverflow.com/questions/37700926/using-jsoup-to-access-html-but-receives-error-code-503
Using Jsoup to access HTML but receives error code 503
I have been trying to access KissAnime however, i kept receiving this error: org.jsoup.HttpStatusException: HTTP error fetching URL. Status=503 When i tried another URL eg. https://www.google.c...
stackoverflow.com
https://jsoup.org/apidocs/org/jsoup/Connection.html
Connection (jsoup Java HTML Parser 1.15.4 API)
ignoreContentType Connection ignoreContentType(boolean ignoreContentType) Ignore the document's Content-Type when parsing the response. By default this is false, an unrecognised content-type will cause an IOException to be thrown. (This is to prevent pro
jsoup.org
'공부' 카테고리의 다른 글
[spark] zipWithIndex (0) | 2023.02.26 |
---|---|
[spark] broadcast nested loop join (0) | 2023.02.26 |
[terraform] command (init, apply, plan) (0) | 2023.02.26 |
[hive] `VARCHAR` vs `STRING` -> STRING is winner (0) | 2023.02.26 |
[aws] install `Amazon Corretto 11` (0) | 2023.02.26 |
- Total
- Today
- Yesterday
- 클루지
- 모델y
- 어떻게 능력을 보여줄 것인가?
- 메디파크 내과 전문의 의학박사 김영수
- 김달
- COUNT
- 할인
- 인스타그램
- 테슬라 레퍼럴 코드 확인
- 테슬라 리퍼럴 코드 생성
- 유투브
- 테슬라 크레딧 사용
- 책그림
- 모델 Y 레퍼럴
- Kluge
- 테슬라
- Bot
- 개리마커스
- 테슬라 리퍼럴 코드 혜택
- wlw
- follower
- 테슬라 레퍼럴
- 테슬라 리퍼럴 코드
- 레퍼럴
- 팔로워 수 세기
- 테슬라 레퍼럴 적용 확인
- 연애학개론
- 테슬라 추천
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |