HttpRequests

Get ByteArray, String or CharSequence

Convenience methods provided:

fun example() {
  HttpRequests.request("https://example.com").readChars()
}

Get Reader

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 */ }
}

Handle HTTP Errors

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
  }
}

Customize User-Agent

By default header User-Agent is not set,