Android 无效的查询参数:无效的编码

Android 无效的查询参数:无效的编码,android,kotlin,retrofit2,multipartform-data,okhttp3,Android,Kotlin,Retrofit2,Multipartform Data,Okhttp3,我尝试通过改装/多部分上传图片JPG。Api总是返回带有无效查询参数的代码400:无效编码 我不知道怎么了 我的界面: @Headers("Content-type: application/x-www-form-urlencoded", "Accept: application/vnd.mypb+json; version=7") @POST("/alerts/actions/unknown_pid") @Multipart fun uploadPhoto(@Part body: Multip

我尝试通过改装/多部分上传图片JPG。Api总是返回带有无效查询参数的代码400:无效编码 我不知道怎么了

我的界面:

@Headers("Content-type: application/x-www-form-urlencoded", "Accept: application/vnd.mypb+json; version=7")
@POST("/alerts/actions/unknown_pid")
@Multipart
fun uploadPhoto(@Part body: MultipartBody.Part): Call<String?>
My webservice上载照片方法:

fun uploadPhoto(bitmap: Bitmap) {
    val imageFile = File(context.cacheDir, "image.jpg")

    val baos = ByteArrayOutputStream()
    bitmap.compress(Bitmap.CompressFormat.JPEG, 15, baos)
    val byteArray = baos.toByteArray()

    val fos = FileOutputStream(imageFile)
    fos.write(byteArray)
    fos.flush()
    fos.close()

    val filePart = RequestBody.create(MediaType.parse("image/*"), imageFile)
    val body = MultipartBody.Part.createFormData("document[file]", "photo.jpg", filePart)

    service.uploadPhoto(body).enqueue(object : LoggingCallback<String?>() {
        override fun onSuccess(responseBody: String?) {
            EventBus.getDefault().post(OnPhotoUploadSuccessfulEvent())
        }

        override fun onFailure(response: Response<String?>) {
            EventBus.getDefault().post(OnPhotoUploadFailedEvent())
        }
    })
}
查尔斯的答复:
您的标题不正确

您可以删除标题内容类型:application/x-www-form-urlencoded


或者您应该改为内容类型:多部分/表单数据

我的天啊……我尝试了各种内容类型,但都没有效果。现在我完全删除了内容类型,它可以正常工作了。你救了我一天!非常感谢。