[Solved] Send JWE, as request body, with Retrofit

Sparsh Dutta Asks: Send JWE, as request body, with Retrofit
I am using Retrofit to send request as encrypted JWT (JWE) to an API.

My service interface is:

Code:
interface APICallService {

    @Headers("Content-Type: application/jwt")
    @POST("/v1/api/dp_checkkyc")
    fun getKycCompliantStatus(@Header("Authorization") accessToken:String,  kycStatusRequest: KycStatusRequest): Call<KycCompliantBaseResponse>

}

My KycStatusRequest class is:

Code:
data class KycStatusRequest(var encryptedJWT : String)

I am hitting the API with:

Code:
fun getEKycCompliantStatus(accessToken:String, pan:String) {
            var jwe = EncryptedJWTGenerator(pan).jweString //This JWE works fine with Postman
            val kycStatusRequest = KycStatusRequest(jwe)
            val call = getServiceInstance().getKycCompliantStatus("Bearer ${accessToken.trim()}", kycStatusRequest)
            call.enqueue(object : Callback<KycCompliantBaseResponse> {
                override fun onResponse(call: Call<KycCompliantBaseResponse>, response: Response<KycCompliantBaseResponse>) {
                    if (response.code() == 200) {
                        val kycResponse = response.body()!!
                        if (kycResponse.Response.F_PAN_STATUS.equals("ok", true))
                            isKycCompliant = true

                        else if (kycResponse.Response.F_PAN_STATUS.equals("invalid", true))
                            isKycCompliant = false

                    }

                    else
                        Toast.makeText(context,"Check kyc API failure!", Toast.LENGTH_LONG).show()    
                }

                override fun onFailure(call: Call<KycCompliantBaseResponse>, t: Throwable) {
                    Toast.makeText(context,"Check kyc API failure!", Toast.LENGTH_LONG).show()
                }
            })
        }

On using the above code I get 'Internal Server Error'. But on using the same jwe I used above with postman, API works fine.

I am suspecting that I am getting this error as I am wrapping my JWE in KycStatusRequest class before sending, which I think will convert it into a JSON with key-value pair.

How do I send my JWE as a raw text without any key-value pair?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.