package com.util; import com.google.gson.JsonObject; import net.sf.json.JSONObject; import okhttp3.*; import java.io.File; import java.io.IOException; import java.util.Map; public class OkHttpUtil { public static JSONObject doPost(String url, File file , Map<String, String> maps) throws IOException { OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("text/plain"); MultipartBody.Builder builder= new MultipartBody.Builder().setType(MultipartBody.FORM); if(maps==null){ if(file!=null){ builder.addFormDataPart("recordFile",file.getPath(), RequestBody.create(MediaType.parse("application/octet-stream"), new File(file.getPath()))); } }else{ for (String key : maps.keySet()) { String str = maps
postman传文件和参数
最新推荐文章于 2024-02-28 14:17:35 发布