android - 改造:带 json 的多部分
问题描述
我想发送带有 Multipart 表单数据的 json。
我熟悉标题 + 多部分表单数据,但标题问题不允许发送中文/希伯来语字符。所以我需要为此使用json。
谁能帮我解决这个问题?
我的 JSON ::
{
"agent": "ee",
"phone": "123",
"manager": "234"
}
具有带有“图像”参数的 Multipart 的表单数据。
解决方案
尝试这个
RequestBody fileBody = RequestBody.create(MediaType.parse("image/*"), selectedImage /* file name*/);
MultipartBody.Part filePart = MultipartBody.Part.createFormData("image", selectedImage.getName(), fileBody);
agent = RequestBody.create(MediaType.parse("text/plain"), "<agent-value>");
phone = RequestBody.create(MediaType.parse("text/plain"), "<phone-value>");
manager = RequestBody.create(MediaType.parse("text/plain"), "<manager-value>");
在你的界面类中
@Multipart
@POST(UPDATE_PROFILE_IMAGE)
Call<JsonObject> updateImage(@Part MultipartBody.Part image,
@Part("agent") RequestBody agent,
@Part("phone") RequestBody phone,
@Part("manager") RequestBody manager);
它适用于所有设备
推荐阅读
- javascript - event.preventDefault() 不适用于 keyCode 229?
- c++ - 如何验证类方法签名?
- codeigniter - codeigniter - 如何将表列中的值相加
- django - 有什么方法可以在 Django 中安排类似于 MySQL 事件的事件?
- c - __libc_init_array 在设置堆栈指针之前使用堆栈指针进行写入
- javascript - 根据值隐藏列表项
- vim - 如何使用 tmux 在 iTerm2 中获得类似 Vim 的滚动(历史和屏幕滚动)
- angular - VS Code 显示 .toDate() 函数将 Firebase 时间戳转换为日期的错误
- sql - 何在 sql 中使用 to_date 转换日期“2019-12-06 04:21:13.0”
- coldfusion - 识别从网站页面或直接从浏览器地址栏中点击的网站 URL