Search code examples
androidretrofitpostmancyrillic

Retrofit 2.1 Posting Cyrillic Field Error


I am using Retrofit 2.1. But when I post a field that contains cyrillic word, it gives an empty response, however it should return 2-3 items. Here is the api:

@FormUrlEncoded
@POST("my_awesome_base_url")
Call<Questions> getQuestions(@Field(value = "rowsdata", encoded = false) String rowsdata);

And the rowsdata contains some cyrillic word that db should search and respond similar results. Here is an example rowsdata:

rowsdata = {"code":"-4","start":"1","where":"where  short_question like 'Вақт' ","end":"2"}

In the rowsdata, Вақт is in cyrillic, but it is somehow encoding it to some chars so that server is giving me an empty list.

I checked this on Postman, and it gave me the desired results, but when I send a request using Retrofit, it is responding like nothing is found...


Solution

  • Probably an encoding issue.

    From developers site :

    A String represents a string in the UTF-16 format in which supplementary characters are represented by surrogate pairs (see the section Unicode Character Representations in the Character class for more information). Index values refer to char code units, so a supplementary character uses two positions in a String.

    Try encoding the string into UTF-8, make sure your file is UTF-8 as well (default in Android Studio I think).