Android(安卓)OKhttp 上传文件袋参数
16lz
2022-04-04
public void uploadImage(String interfaceUrl,String filePath,String idCardNo) {
Logger.d(“interfaceUrl:”+interfaceUrl);
OkHttpClient mOkHttpClient = new OkHttpClient();
File file = new File(filePath);
if (file.exists()){
MultipartBody.Builder builder = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(“aac002”,idCardNo)
.addFormDataPart(“file”, file.getName(),
RequestBody.create(MediaType.parse(“image/*”), file));
RequestBody requestBody = builder.build(); Request request = new Request.Builder() .url(interfaceUrl) .post(requestBody) .build(); Call call = mOkHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { Log.e(TAG, "onFailure: "+e ); } @Override public void onResponse(Call call, Response response) throws IOException { ResponseBody body = response.body(); String output = body.string(); Log.e(TAG, "成功:"+output); } }); }else{ Logger.e(TAG, "文件为空"); }}
更多相关文章
- Android日志服务 记录日志
- AndroidManifest.xml文件详解(uses-configuration)
- android studio Error:Unable to start the daemon process
- android studio Error:Unable to start the daemon process
- [置顶] android调用系统相机拍照并保存在本地
- Android(安卓)AES 文件加密解密
- Android(安卓)Studio设置gradle代理
- Android(安卓)文件打开方式
- NPM 和webpack 的基础使用