http post 요청을 시도하고 있지만 이해할 수없는 이유로 실패합니다.
object KtorClient {
val client = HttpClient() {
install(JsonFeature) {
serializer = KotlinxSerializer()
}
}
}
suspend fun createOwner(url : String = "http://localhost:112/company/owner/register", ownerMapper: OwnerMapper) {
println(ownerMapper)
client.post<Unit>(url){
body = ownerMapper
}
}
BlockquoteIllegalStateException {message_8yp7un $ _0 : "본문을 보내지 못했습니다. 콘텐츠에 유형 : OwnerMapper 클래스가 있지만 OutgoingContent가 필요합니다.", cause_th0jdv $ _0 : null, 스택 : "captureStack↵Exception↵RuntimeException↵IllegalSta… ↵↵↵↵↵↵↵↵↵↵↵↵ ↵↵↵↵↵↵↵↵↵promiseReactionJob @ [native code] ", 이름 :"IllegalStateException "}
직렬화 플러그인을 추가 한 후 다음 오류가 발생합니다.
"OwnerMapper 클래스에 대한 인수없는 직렬 변환기를 찾을 수 없습니다. 목록과 같은 일반 클래스의 경우 직렬 변환기를 명시 적으로 제공하십시오."
나는 공식적인 예를 따랐지만 실행할 수 없습니다. Kotlin / Js를 사용 중이며 위의 오류는 브라우저에서 발생합니다.
val client = HttpClient() {
install(JsonFeature){
serializer = KotlinxSerializer()
}
}
@Serializable
data class OwnerLoginMapper(
val email: String? = null,
val username: String? = null,
val number: String? = null,
val credential: String
)
@Serializable
data class Token(
val token : String
)
var response = client.post<Token>(url){
contentType(ContentType.Application.Json)
body = ownerMapper
}
println(response.token)
다음 종속성을 추가하십시오.
implementation("io.ktor:ktor-client-json-js:1.3.2")
implementation("io.ktor:ktor-client-serialization-js:1.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:0.20.0")
이 플러그인 적용 :
kotlin("plugin.serialization") version "1.3.70"
추신 : 적절한 버전 번호를 선택하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다