Created
March 19, 2021 09:05
-
-
Save chumpa/7efccbf5ae9ebe3083960a57c22564f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
для себя памятка про ктор-клиент для ЦПИ