我正在开发一个应用程序,用户可以发布文本、img或视频。一切正常。但有时当我想发布一个字母或表情符号时,它会给我错误Unprocessable Content
。
ERROR:: Response{protocol=http/1.1, code=422, message=Unprocessable Content, url=http://myUrl.com}
我的RetrofitBuiler对象:
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接口:
@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>
1条答案
按热度按时间f0brbegy1#
你必须在“UNICODE”中编码表情符号/或任何非文本内容。将它们作为UNICODE字符串发送到服务器,当显示它们时将它们解码回来。Here's the reference link that can help you get started.