io.api.bloxy.executor.impl.HttpClient.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bloxy-api Show documentation
Show all versions of bloxy-api Show documentation
Kotlin & Java Library for all available Bloxy API endpoints
package io.api.bloxy.executor.impl
import io.api.bloxy.executor.IHttpClient
import java.net.URL
import java.util.stream.Collectors
/**
* @see IHttpClient
*
* @author GoodforGod
* @since 16.11.2018
*/
class HttpClient @JvmOverloads constructor(
private val connectTimeout: Int = 8000,
private val readTimeout: Int = 0
) : IHttpClient {
companion object {
private val headers: Map = hashMapOf(
"Accept-Language" to "en",
"Accept-Encoding" to "deflate",
"Accept-Charset" to "UTF-8",
"User-Agent" to "Chrome/68.0.3440.105",
"Content-Type" to "application/x-www-form-urlencoded"
)
}
override fun get(url: String): String {
URL(url).openConnection().apply {
readTimeout = [email protected]
connectTimeout = [email protected]
headers.forEach { e -> setRequestProperty(e.key, e.value) }
getHeaderField("Location")?.let { return get(it) }
}.getInputStream().use {
return it.bufferedReader().lines().collect(Collectors.joining())
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy