Created
July 16, 2021 12:50
-
-
Save scaramangado/7a6277f30568d55b3ed6300f7e36eae2 to your computer and use it in GitHub Desktop.
Open BingoSync Rooms
This file contains 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 java.net.CookieManager | |
import java.net.URI | |
import java.net.http.HttpClient | |
import java.net.http.HttpRequest | |
import java.net.http.HttpResponse | |
val url = "https://bingosync.com" | |
val cookieManager = CookieManager() | |
val client: HttpClient = HttpClient.newBuilder() | |
.cookieHandler(cookieManager) | |
.build() | |
val pageRequest: HttpRequest = HttpRequest.newBuilder() | |
.GET() | |
.uri(URI(url)) | |
.build() | |
val csrfToken: String = client.send(pageRequest, HttpResponse.BodyHandlers.ofString()) | |
.body() | |
.also { println("page: $it") } | |
.lineSequence() | |
.findLast { it.contains("name='csrfmiddlewaretoken'") }!! | |
.also { println("HTML: $it") } | |
.replace(Regex("^.*value='"), "") | |
.replace(Regex("' />.*"), "") | |
cookieManager.cookieStore.cookies.forEach { | |
println("${it.name} = ${it.value}") | |
} | |
println("CSRF: $csrfToken") | |
val body = | |
"csrfmiddlewaretoken=$csrfToken&room_name=name&passphrase=pass&nickname=nick&game_type=1&variant_type=1&custom_json=&lockout_mode=1&seed=123&is_spectator=on&hide_card=on" | |
println(body) | |
val request: HttpRequest = HttpRequest.newBuilder() | |
.POST(HttpRequest.BodyPublishers.ofString(body)) | |
.uri(URI(url)) | |
.header("Content-Type", "application/x-www-form-urlencoded") | |
.build() | |
client.send(request, HttpResponse.BodyHandlers.ofString()) | |
.also { | |
println("HTTP ${it.statusCode()}") | |
it.headers().map().forEach { e -> | |
println("${e.key}: ${e.value}") | |
} | |
} | |
.body().run { println(this) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment