Skip to content

POST without content-type #940

@LiushuiXiaoxia

Description

@LiushuiXiaoxia

Ktorfit version

2.6.4

What happened and how can we reproduce this issue?

The body type is: class com.xxx.api.TryOnClothingReq, with Content-Type: null.
If you expect serialized body, please check that you have installed the corresponding plugin(like ContentNegotiation) and set Content-Type header.

ktor = "3.3.1"
ktorfitLib = "2.6.4"
ktorfitPlugin = "2.6.4"

What did you expect to happen?

It's ok

interface ClothingApi {
	@Headers("Content-Type: application/json")
	@POST("queen/game/try-on-clothing")
	suspend fun tryOnClothing(@Body req: TryOnClothingReq): ApiResp<TryOnClothingData>
}

or

install(DefaultRequest) {
	contentType(ContentType.Application.Json)
}

Is there anything else we need to know about?

interface ClothingApi {
	@POST("queen/game/try-on-clothing")
	suspend fun tryOnClothing(@Body req: TryOnClothingReq): ApiResp<TryOnClothingData>
}
@OptIn(InternalKtorfitApi::class)
public class _ClothingApiImpl(
  private val _ktorfit: Ktorfit,
) : ClothingApi {

  override suspend fun tryOnClothing(req: TryOnClothingReq): ApiResp<TryOnClothingData> {
    val _ext: HttpRequestBuilder.() -> Unit = {
        this.method = HttpMethod.parse("POST")
        url{
        takeFrom(_ktorfit.baseUrl + "queen/game/try-on-clothing")
        }
        setBody(req) 
        }
    val _typeData = TypeData.createTypeData(
    typeInfo = typeInfo<ApiResp<TryOnClothingData>>(),
    )
    return _helper.suspendRequest(_typeData,_ext)!!
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions