网上一搜都是上传图片的...
摸索了好一会儿, 调出来了
/*
* 生成表单数据
* */
private RequestBody formData(JSONObject params) {
//json参数
MultipartBody.Builder requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM);
// 迭代器
Iterator it = params.keys();
String key = null;//键
String val = null;//值
while(it.hasNext()){//遍历JSONObject
// 获取key
key = (String) it.next().toString();
val = params.optString(key);
requestBody.addFormDataPart(key, val);
}
return requestBody.build();
}
RequestBody requestBody = formData(params);
okhttp3.Request request = this.getBuilder(url).post(requestBody).build();
网友评论