Ktorfit icon indicating copy to clipboard operation
Ktorfit copied to clipboard

POST without content-type

Open LiushuiXiaoxia opened this issue 1 month ago • 2 comments

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)!!
  }
}

LiushuiXiaoxia avatar Nov 04 '25 05:11 LiushuiXiaoxia

I'm having the exact same issue, is there a workaround for this ?

fpillet avatar Nov 14 '25 09:11 fpillet

I can not implement this, at compile time i have no way to know what Ktor plugins are installed

Foso avatar Nov 15 '25 10:11 Foso