Jan
09/10/2021, 10:56 AMJan
09/10/2021, 10:56 AMException in thread "DefaultDispatcher-worker-5" java.net.BindException: Cannot assign requested address: connect
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:482)
at sun.nio.ch.Net.connect(Net.java:474)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:647)
at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:32)
at io.ktor.network.sockets.ConnectUtilsJvmKt.connect(ConnectUtilsJvm.kt:19)
at io.ktor.network.sockets.TcpSocketBuilder.connect(TcpSocketBuilder.kt:38)
at io.ktor.client.engine.cio.ConnectionFactory.connect(ConnectionFactory.kt:24)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invokeSuspend(Endpoint.kt:184)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:100)
at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:148)
at kotlinx.coroutines.TimeoutKt.withTimeoutOrNull(Timeout.kt:104)
at io.ktor.client.engine.cio.Endpoint.connect(Endpoint.kt:192)
at io.ktor.client.engine.cio.Endpoint.access$connect(Endpoint.kt:28)
at io.ktor.client.engine.cio.Endpoint$makeDedicatedRequest$1.invokeSuspend(Endpoint.kt:105)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)Jan
09/10/2021, 10:57 AMJan
09/10/2021, 1:41 PMJan
09/10/2021, 1:50 PMval result = http.post<String>("https://discord.com/api/v9/users/@me/channels", body = buildJsonObject {
put("recipient_id", 285418000734093312)
}.toString()) {
header("Authorization", "")
header("User-Agent", "")
}
println(result)
New error:
Exception in thread "main" io.ktor.client.features.ClientRequestException: Client request(https://discord.com/api/v9/users/@me/channels://localhost/) invalid: 404 Not Found. Text: "{"message": "404: Not Found", "code": 0}"
Why is there a localhost now??Aleksei Tirman [JB]
09/10/2021, 1:58 PMHttpClient.post overload you use is scheme so it adds ://localhost to it. Here is a correct way of making a POST request with a body:
val client = HttpClient(Apache)
val result = client.post<String>("https://discord.com/api/v9/users/@me/channels") {
body = buildJsonObject {
put("recipient_id", 285418000734093312)
}.toString()
header("Authorization", "")
header("User-Agent", "")
}
println(result)Jan
09/10/2021, 2:27 PM