Skip to content

Instantly share code, notes, and snippets.

@chumpa
Created March 19, 2021 09:05
Show Gist options
  • Select an option

  • Save chumpa/7efccbf5ae9ebe3083960a57c22564f1 to your computer and use it in GitHub Desktop.

Select an option

Save chumpa/7efccbf5ae9ebe3083960a57c22564f1 to your computer and use it in GitHub Desktop.
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.features.*
import io.ktor.client.features.cookies.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
val uri = "https://e000001-tmn.hci.ru1.hana.ondemand.com/api/v1"
suspend fun main(args: Array<String>): Unit {
var token = "Fetch"
val client = HttpClient(CIO) {
engine {
threadsCount = 2
}
install(HttpCookies) {
storage = AcceptAllCookiesStorage()
}
defaultRequest {
header("Accept", "application/json")
header("X-CSRF-Token", token)
}
}
val h1:HttpResponse = client.head(uri) {
header("Authorization", "Basic cccccccccccccccccccccccccccccccc")
}
token = h1.headers.get("X-CSRF-Token") ?: ""
println(token)
val g1:HttpResponse = client.get("$uri/ServiceEndpoints?\$top=1") {
}
println(g1.readText())
client.close()
}
@chumpa

chumpa commented Mar 19, 2021

Copy link
Copy Markdown
Author

для себя памятка про ктор-клиент для ЦПИ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment