Retrofit 2.1 发布 Cyrillic 字段错误
Retrofit 2.1 Posting Cyrillic Field Error
我正在使用 Retrofit 2.1
。但是当我 post 一个包含西里尔字母的字段时,它会给出一个空的响应,但是它应该 return 2-3 个项目。这是 api:
@FormUrlEncoded
@POST("my_awesome_base_url")
Call<Questions> getQuestions(@Field(value = "rowsdata", encoded = false) String rowsdata);
并且 rowsdata 包含一些西里尔字母,db 应该搜索并响应类似的结果。这是一个例子 rowsdata
:
rowsdata = {"code":"-4","start":"1","where":"where short_question like 'Вақт' ","end":"2"}
在 rowsdata
中,Ваят 是西里尔字母,但它以某种方式将其编码为一些字符,因此服务器给我一个空列表。
我在 Postman 上检查过,它给了我想要的结果,但是当我使用 Retrofit 发送请求时,它的响应就像什么也没找到一样...
可能是编码问题。
来自 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.
尝试 encoding the string 转换为 UTF-8,确保您的文件也是 UTF-8(我认为 Android Studio 中的默认设置)。
我正在使用 Retrofit 2.1
。但是当我 post 一个包含西里尔字母的字段时,它会给出一个空的响应,但是它应该 return 2-3 个项目。这是 api:
@FormUrlEncoded
@POST("my_awesome_base_url")
Call<Questions> getQuestions(@Field(value = "rowsdata", encoded = false) String rowsdata);
并且 rowsdata 包含一些西里尔字母,db 应该搜索并响应类似的结果。这是一个例子 rowsdata
:
rowsdata = {"code":"-4","start":"1","where":"where short_question like 'Вақт' ","end":"2"}
在 rowsdata
中,Ваят 是西里尔字母,但它以某种方式将其编码为一些字符,因此服务器给我一个空列表。
我在 Postman 上检查过,它给了我想要的结果,但是当我使用 Retrofit 发送请求时,它的响应就像什么也没找到一样...
可能是编码问题。
来自 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.
尝试 encoding the string 转换为 UTF-8,确保您的文件也是 UTF-8(我认为 Android Studio 中的默认设置)。