Convenience methods provided:
readBytes
readString
readChars
fun example() { HttpRequests.request("https://example.com").readChars() }
If you have custom read logic, you can use reader
or getReader(ProgressIndicator)
:
fun example() { HttpRequests.request("https://example.com") .connect { it.reader.buffered().lines() /* use reader somehow and produce some result */ } }
Call of some read*
method throws HttpRequests.HttpStatusException
exception.
fun example(): CharSequence? { try { return HttpRequests.request("https://example.com") .readChars() } catch (e: HttpRequests.HttpStatusException) { return null } }
By default header User-Agent
is not set,
productNameAsUserAgent()
to set to current product name and version (e.g. IntelliJ IDEA/2018.2
).userAgent(String)
to set to arbitrary value.