Skip to content

The request cannot be sent with the parameter ReqeustInit. #70

@QingMingKt

Description

@QingMingKt

When sending a request using window.fetch, if you use ReqeustInit, you will not be able to send the request, even if RequestInit does not write anything.

(Because the picture cannot be uploaded, post the code.)

object ApiUtil {
    suspend fun login(username: String, password: String): ResultUDM<JsString> {
        val response = window.fetch(
            "http://127.0.0.1:9002/user/login", RequestInit(
                method = "POST", body = LoginUser(username, password)
            )
        ).await<Response>()
        return response.json().await()
    }
}

Browser console error:JsException: Exception was thrown while running JavaScript code

If the ReqeustInit parameter is removed, it can run normally.

Version information:

[versions]
androidx-lifecycle = "2.8.0"
compose-plugin = "1.6.11"
junit = "4.13.2"
kotlin = "2.0.20"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-lifecycle-viewmodel = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-viewmodel", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime-compose = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }

[plugins]
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions