0

I am developing an app where users can post text, img or video. Everything working fine. But sometimes it's giving me the error Unprocessable Content, when I want to post a single letter or emoji.

ERROR:: Response{protocol=http/1.1, code=422, message=Unprocessable Content, url=http://myUrl.com}

please see the attched img

My RetrofitBuiler Object:

 var gson: Gson = GsonBuilder()
        .setLenient()
        .setDateFormat("yyyy-MM-dd hh:mm:ss.S")
        .create()

    private var httpClient =
        OkHttpClient.Builder().retryOnConnectionFailure(true).connectTimeout(60, TimeUnit.SECONDS)
            .build()

    private val retrofit: Retrofit by lazy {
        Retrofit.Builder().baseUrl(getBaseUrl())
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addConverterFactory(NullConvertfactory()).client(httpClient).build()
    }

    val API_SERVICE: FansApiService by lazy {
        retrofit.create(FansApiService::class.java)

    }

APi InterFace:

@Headers("Accept:application/json")
@Multipart
@POST("endurlHere")
fun createPost(
    @Header("Authorization") token: String,
    @Part("text_content") text_content: RequestBody,
    @Part imageList: List<MultipartBody.Part>
): Call<CreatePostResponse>
its-me-mahmud
  • 690
  • 1
  • 7
  • 14
monjur
  • 19
  • 7

1 Answers1

0

You have to encode emoji / or any non textual content for that matter in "UNICODE". Send them to server as UNICODE string and when displaying them decode them back. Here's the reference link that can help you get started.